Forum Moderators: phranque

Message Too Old, No Replies

Redirect www and non-www to subdomain

htaccess redirection

         

Saguaro2

8:52 pm on Sep 30, 2007 (gmt 0)

10+ Year Member



I am setting up a new website and want to 301 redirect www.example.com and example.com to subdomain.example.com

I found the following code on the internet that seems to work fine but wanted to make sure that Google would see this as a good 301 redirect?

RewriteEngine On
Options +FollowSymlinks
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^ [subdomain.example.com...] [R=301,L]

Does anyone see any problems or unintended consequences from this code?

g1smd

9:46 pm on Sep 30, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The [R=301] tells you what sort of redirect it is.

Your redirect only redirects to the root of the subdomain. However it redirects to that subdomain without a trailing / on the end, and the server will probably then try to correct that by applying a second redirect to add the / on the end of the URL. Add the / within your redirect to fix that from happening.

Do you want the redirect to apply only to the root of the old domain, or do you want it to apply to all of the files and folders within the site?

If you want it to apply to all files and folders within, do you want the filepath to be preserved in the redirect, or do you want to redirect all old paths to the root of the subdomain?

Saguaro2

12:04 am on Oct 1, 2007 (gmt 0)

10+ Year Member



I will add the trailing / to the URL so it will look like this:
RewriteRule^http://subdomain.example.com/ [R=301,L]

>Do you want the redirect to apply only to the root of the old domain, or do you want it to apply to all of the files and folders within the site?<

Well I guess with this redirect I am just trying to be careful. This site currently has only an index page on the subdomain and no links to any page yet. The structure of the site will be.

subdomain.example.com
subdomain.example.com/subdirectory/

I don't plan to have any other subdomains but will have multiple subdirectories and will not use the address www.example.com or example.com

I guess it would be best to just redirect all files and folders within example.com and www.example.com to the root of the subdomain.

Thanks for your help g1smd.