1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Mod_Rewrite question.

Discussion in 'HTML, Graphics & Programming' started by malef!c, 10 Mar 2010.

  1. malef!c

    Wise Guy

    Joined: 27 Jun 2006

    Posts: 1,473

    Evening all - fairly new to this, but I have the following file stucture on some webspace (helping a friend, not my site or structure!)

    public_html (www.domain.com)

    At the moment, the htaccess file has the following lines in it to push all requests to the domain name to directory1. IE: www.domain.com ->www.domain.com/directory1

    This worked fine until he added directory 2.

    Now if he browses to www.domain.com/directory2 firefox throws an error:

    "Firefox has detected that the server is redirecting the request for this address in a way that will never complete."

    which I am guessing is something to do with the htaccess file.

    I am no master on htaccess but I tried the following but it still doesn't work:

    Options +FollowSymLinks
    RewriteEngine on 
    RewriteCond %{REQUEST_FILENAME} -f [NC,OR]
    RewriteCond %{REQUEST_FILENAME} -d [NC] 
    RewriteRule (.*) http://www.domain.com/directory1/$1 [R=301,L]

    Any help kindly accepted :)
  2. V4NT0M


    Joined: 18 Jan 2007

    Posts: 19,708

    Location: Land of the Scots

    That rewrite doesn't even work if I upload it to a site...

    Is it terribly important for it to be a rewrite? i.e. for SEO purposes? I would just use a php redirect.

    Just make an index.php in the root dir and put:
    'Location: http://domain.com/directory1/' ) ;
    That's how I always do these kinds of things, is there a reason why this redirect is in place in the first place that can't be fixed?
  3. malef!c

    Wise Guy

    Joined: 27 Jun 2006

    Posts: 1,473

    I don't really know why it has to be done in the htaccess file, I foolishly thought I would give a friend a hand (if only I knew it was the voodoo that is rewrite I would of run away!)

    I may try to push him the way you suggested as its easier and I understand it!

  4. Pho


    Joined: 18 Oct 2002

    Posts: 9,224

    Location: Derbyshire

    Do you want all requests which go to Directory2 to also be sent to Directory1?

    Using the rewrite above if I go to:

    I get forwarded to:

    without any loop errors.

    Have you got another .htaccess file in Directory1 ?
  5. malef!c

    Wise Guy

    Joined: 27 Jun 2006

    Posts: 1,473

    Thanks for that - no other htaccess anywhere (I had a good look as I was pulling my hair out!)

    In the end I persuaded him to dump the htaccess and go with a PHP redirect, so its now happy (and a lot easier for me!!)
  6. suarve


    Joined: 8 Oct 2005

    Posts: 4,185

    Location: Midlands, UK

    He's using a 301, so it is for SEO purposes :)
  7. gord


    Joined: 18 Oct 2003

    Posts: 19,356

    Location: Midlands

    Still doable in PHP though.

    Header( "HTTP/1.1 301 Moved Permanently" );
    Header( "Location: http://www.new-url.com" );
    But yeh, I would change to this code as Google will find that site as 302.