Get values with .htaccess url rewrite

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chathura86
    New Member
    • May 2007
    • 227

    #1

    Get values with .htaccess url rewrite

    hi

    i placed a .htacess file to rewrite page url

    e.g

    RewriteRule index.htmls$ index.php

    is it possible to get the url parameters with rewrited url

    eg

    if the url is index.htmls?nam e=foo

    then i want to get the value as it is on normal php file
    $_GET['name']

    please explain me if this is possible
    i cannot write a separate rule for this because the parameters are coming form another system so it has to be in for format of

    <url>?name=foo. .....

    thanks in advanced

    chathura
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    it is possible as long as you can write a RegEx for it. (though I don’t see the use for that).

    Comment

    • TheServant
      Recognized Expert Top Contributor
      • Feb 2008
      • 1168

      #3
      Something like:
      Code:
      RewriteRule ^index.htmls?(get)$ index.php?$1
      Not sure if that works, but you can do as you requested.
      Have a look here for some tips and some things that you can do with mod rewrite.

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        Hey.

        This should happen automatically.
        If you have a rule that says:
        Code:
        RewriteRule ^index.htmls$ index.php
        And you do /index.htmls?param=value

        The code in index.php should get the $_GET['param'] value.

        At least, that's how it works on my test server. (Apache 2.2.11 on Win7)

        Comment

        • chathura86
          New Member
          • May 2007
          • 227

          #5
          After some researches i found the solution

          RewriteRule index.shtml index.php [QSA]

          [QSA] appends the original url parameters as it is.

          eg.

          index.shtml?foo 1=bar1&foo2=bar 2

          this will be converted to

          index.php?foo1= bar1&foo2=bar2

          so on the php file you can get them as usual ($_GET)

          regards
          Chathura Bamunusinghe

          Comment

          Working...