.htaccess Rewrite rule in .htaccess

Discussion in 'Apache' started by nyspy, May 12, 2012.

  1. #1
    So I've got this little issue I'm hoping can be solved by someone here.

    I'm trying to redirect anything like http://xyz.com/?/foo/ to http://xyz.com/foo

    I can't figure out how to write the redirectmatch 301 rule to eliminate the /?/

    It's been a hopeless endeavor.

    Any help would be greatly appreciated.

    Thanks.

    PK
     
    nyspy, May 12, 2012 IP
  2. nikhilrajr

    nikhilrajr Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Try this

    Options +FollowSymlinks
    RewriteEngine on
    redirect 301 /?/foo/ http://xyz.com/foo/
     
    nikhilrajr, May 16, 2012 IP
  3. nyspy

    nyspy Peon

    Messages:
    2
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I did some research and it turns out that the Redirect rule won't work. (Didn't even bother trying it).

    It's the fact that the ? is a special query string character so the only way to fix it is to use RewriteCond. I'm going to start playing with it today.

    Thanks for the suggestion though.
     
    nyspy, May 17, 2012 IP
  4. MarkElse101

    MarkElse101 Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    you could try

    RewriteEngine on


    RewriteRule ^/foo/$ /?/foo/ [L]
     
    MarkElse101, May 17, 2012 IP
  5. nikhilrajr

    nikhilrajr Peon

    Messages:
    45
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #5
    How did that /?/ come there?

    example.com and example.com/?/ will return the home page.
    example.com/?/anything.html will also return the home page.
     
    nikhilrajr, May 18, 2012 IP
  6. gregBS

    gregBS Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    the ? character should be escaped. try: RewriteRule ^/\?/(.*)$ /$1 [L]
     
    gregBS, May 18, 2012 IP