Forum Moderators: phranque

Message Too Old, No Replies

.htaccess redirect 301 to folder to subdomain

syntax question

         

Lucas

6:25 am on Jul 12, 2004 (gmt 0)

10+ Year Member



earlier [webmasterworld.com], i asked about using .htaccess for 301 redirects from example.com/folder/ to folder.example.com. i was told to include the following line in my .htaccess file:

^www\.example\.com/folder/(.*) http://folder.example.com/$1

fine. but later i found [tamingthebeast.net] that the following also works:

redirect 301 /folder http://folder.example.com

for easier editing, i have used this second version instead. does it matter?

gergoe

11:33 am on Jul 12, 2004 (gmt 0)

10+ Year Member



It matters yes. If the two webspace uses the same htaccess file (for example when the folder.domain.com is equivalent to www.domain.com/folder (not only because of the redirection)) then it could cause a deadloop if you request the folder.domain.com/folder directory, it inifinitelly redirects to folder.domain.com/folder/folder/...
Unfortunatelly the rule you've posted is not valid because the RewriteRule does not includes the hostname, that needs to be filtered by a RewriteCond, something like this:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^folder/(.*) http://folder.domain.com/$1 [R=301,L]

This will redirect all requests for www.domain.com/folder or domain.com/folder to folder.domain.com.