Forum Moderators: phranque

Message Too Old, No Replies

redirect to www for a single folder

Trial and error isn't working

         

rbacal

3:11 am on Feb 9, 2007 (gmt 0)



I've looked through the archive to see if I can find an answer, and I've tried to fake it/trial and error with no luck (htaccess stuff is a semi mystery).

I want to redirect domain.com/folder to www.domain.com/folder while leaving the rest of the site as is for now.

I've place variations of attempts in .htaccess in domain.com/folder including the following:

Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ [domain.com...] [R=301,L]

I know I don't know what I'm doing, but what do I need to change to get this to work.

Thanks. I know these canonical type questions come up all the time and I'm grateful for any help.

jdMorgan

3:31 am on Feb 9, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If the code is in example.com/.htaccess:

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

Except for the end-anchor on the RewriteCond pattern and the missing slash in the RewriteRule substitution, your code would have worked if located in example.com/folder/.htaccess

If you wish to end-anchor the domain, then you'll need to accommodate the possibility of an appended port number, for example: RewriteCond %{HTTP_HOST} ^example\.com(:[0-9]+)?$ [NC]

Jim

rbacal

4:11 am on Feb 9, 2007 (gmt 0)



Thank you. That gave me enough of a hint to get it working. I actually had it right before, but wasn't getting it because of caching.