Problems doing a URL redirect in .htaccess

Discussion in 'Scripts' started by Nightshade, Nov 24, 2013.

to remove all ads.
  1. Nightshade

    Nightshade New Member

    Messages:
    2
    I've tried dozens of different "solutions" and syntaxing (Redirect, RewriteCond, RewriteRule, Redirect 301, etc) and I just can't get this to work. I often get the "redirect loop" -error or the redirect doesn't work at all, or I get it working with only www.thesite.com and not http://www.thesite.com

    What I want to do:
    When the user goes to mysite.com I want him or her redirected to mysite.com/#anchor
    And if the user goes to www.mysite.com I want him or her redirected to mysite.com/#anchor as well
    ...and if the user goes to http://www.mysite.com I want him or her redirected to mysite.com/#anchor

    ...and yea, I can only get one of these working at a time (or I get a loop).

    My .htaccess file without any redirects:
    Code:
    # enable basic rewriting
    RewriteEngine on
    
    # enable symbolic links
    Options +FollowSymLinks
    
    # enable allowoverride privileges
    <Directory /www/replace/this/with/actual/directory>
     AllowOverride Options
    </Directory>
    
    # do not allow anyone else to read your .htaccess file
    <Files .htaccess>
    deny from all
    </Files>
    
    # forbid viewing of directories
    Options All -Indexes
    
    # disable the server signature- helps with preformance
    ServerSignature Off
    
     
  2. chrishirst

    chrishirst Well-Known Member Staff Member

    Messages:
    2,611
    Document fragment markers '#' are not passed to, or processed by the server. So trying to pass it in a redirect IS going to create a closed loop because site.tld#whatever IS the same as site.tld to an HTTP request.

    The browser processes the fragment marker, so that will have to be handled by javascript or by serverside code because both of those run after the http daemon has processed any htaccess directives and redirects.
     
  3. Nightshade

    Nightshade New Member

    Messages:
    2
    Yea I ended up with a javascript solution, although I wanted to avoid that language as much as possible due to accessability. But my site is not dependent on it though so any users with jscript turned off will still be able to surf around without hassle. I think that is a fair solution.
     

Share This Page