Forum Moderators: phranque
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?
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?
>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.