Forum Moderators: phranque
Im using the following code in my .htaccess (within the /somefolder/ directory):
# Redirect adding trailing slash if missing
rewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
rewriteRule ^(.*)$ http://%{HTTP_HOST}/somefolder/$1/ [R=301,L]
#
# Redirect adding leading www to domain or any subdomain if missing
rewriteCond %{HTTP_HOST} !^www\.
rewriteRule ^(.*)$ http://www.%{HTTP_HOST}/somefolder/$1 [R=301,L]
Adding the www works great, and adding the trailing slash works great for any sub-folder within the /somefolder/ directory, but it doesn't work for the /somefolder/ directory itself.
Hope this isn't too confusing - here's come examples:
my-addy.com.au/somefolder/ => www.my-addy.com.au/somefolder/ - OK
my-addy.com.au/somefolder/foo => www.my-addy.com.au/somefolder/foo/ - OK
my-addy.com.au/somefolder => www.my-addy.com.au/somefolder//home/my-addy/public_html/somefolder/ - ARGH!
also, www.my-addy.com.au/somefolder goes to the same thing as well - ARGH!
I have a feeling that this may be due to a conflict from the .htaccess file in the root folder, which although I can change, would prefer not to (there's a lot of stuff in there for our CMS).
Does anyone have any ideas? Perhaps there's a way to stop the root .htaccess setting being inherited into the /somefolder/ directory?
Thanks guys,
Mitch.
# Redirect adding trailing slash if missing
rewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$
rewriteCond %{REQUEST_URI} !/somefolder$
rewriteRule ^(.*)$ http://%{HTTP_HOST}/support/$1/ [R=301,L]
# Redirect adding leading www to domain or any subdomain if missing
rewriteCond %{HTTP_HOST} !^www\.
rewriteCond %{REQUEST_URI} !/somefolder$
rewriteRule ^(.*)$ http://www.%{HTTP_HOST}/somefolder/$1 [R=301,L]
Works for me, maybe it will help someone else.