Forum Moderators: phranque

Message Too Old, No Replies

Non WWW, Re-direct not working in Directorys

         

editordude

10:14 am on Sep 29, 2005 (gmt 0)

10+ Year Member



Am using this code:

Options +FollowSymlinks -indexes
RewriteEngine on
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.trshady\.com [NC]
RewriteRule ^(.*)$ [trshady.com...] [R=301,L]

Which re-directs all non www. urls to www.domain etc
Now this works fine for most urls on my site but in directorys where I have a .htacess with something like this:

Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)/$ view.php?title=$1

The re-dicrect fails to work.
Any ideas why?

Thanks

jd01

10:55 am on Sep 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You probably need turn use the RewriteOptions inherit directive in your secondary .htaccess file.

Options +FollowSymLinks
RewriteEngine on
RewriteOptions inherit
RewriteRule ^(.*)/$ view.php?title=$1

Hope this helps.

Justin

editordude

11:22 am on Sep 29, 2005 (gmt 0)

10+ Year Member



That did it, thank you.
I thought directorys inherited by default?

Or perhaps this only applies to rewrite rules, either way. Thanks again!

editordude

11:48 am on Sep 29, 2005 (gmt 0)

10+ Year Member



Darn this has only caused more problems.

When redirecting a url from non www. to www instead of changing the url it redirects to what the mod_write disguises.

So where the url looks like this:

domain.com/folder/keyword/

it re-directs to this:

www.domain.com/index.php?variable=keyword

Any ideas why this is happening?

jdMorgan

12:59 pm on Sep 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, because you'll need to do the domain redirect first, and then the internal URL rewrite. Taken the other way, the internal rewrite will be 'exposed' by the domain redirect.

The simplest way to fix it is to put both rules together in one .htaccess file, so that you can explicitly control their order of execution.

So, either duplicate the domain redirect in the subdirectory (and turn inherit back off), or move the static-dynamic URL rewrite to .htaccess in root.

Jim