Mod_Rewrite question.

Associate
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)
|
|___directory1
|
|___directory2

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:

Code:
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 :)
 
Soldato
Joined
18 Jan 2007
Posts
19,845
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:
PHP:
<?php
header( '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?
 
Associate
OP
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 have run away!)

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

Cheers
 

Pho

Pho

Soldato
Joined
18 Oct 2002
Posts
9,324
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:
/directory2/index.php

I get forwarded to:
/directory1/directory2/index.php

without any loop errors.

Have you got another .htaccess file in Directory1 ?
 
Associate
OP
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!!)
 
Soldato
Joined
8 Oct 2005
Posts
4,185
Location
Midlands, UK
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:
PHP:
<?php
header( '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?

He's using a 301, so it is for SEO purposes :)
 
Soldato
Joined
18 Oct 2003
Posts
19,413
Location
Midlands
He's using a 301, so it is for SEO purposes :)

Still doable in PHP though.

Code:
<?
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.
 
Back
Top Bottom