Forum Moderators: phranque
redirect 301 / [domain.com...]
and it isn't working? Also, will this redirect all sub pages (ie. www.site.com/tool.html to www.domain.com/tool.html?
I'm using a linux server.
Derek
Also, don't just use
redirect as some browsers might not support that. Use a real one: To do a 301 redirect, use this:
Options All
RewriteEngine on
RewriteRule ^(.*)/?$ http://domain.com/$1 [R=301,L]
EDIT: $1 is the subpage if any.
Let me know if that works.
R=301 is your redirect type
L means it stops there and redirects, which is what you want.
Redirect 301 / http://www.domain.c[b]om/[/b]
If you are redirecting to a domain that is actually on the same server, then you will need to test the requested hostname, and only do the redirect if it is the 'wrong one'. This requires you to use mod_rewrite [httpd.apache.org] instead of mod_alias, though:
Options +FollowSymLinks
RewriteEngine on
# if not the correct domain
RewriteCond %{HTTP_HOST} ^(www\.)?site\.com [NC]
# redirect to correct domain
RewriteRule (.*) http://domain.com/$1 [R=301,L]
Works for me, even when it's just a single page being redirected to another domain (which has a little more added, but same syntax).
mod_alias is much easier to understand use than mod_rewrite, imho.
Yes it is, and as noted above, a simple Redirect 301 will work as long as the server where the code is installed is different than the server for the domain to be redirected to. However, if the two domains resolve to the same server, then you need mod_rewrite's ability to test the requested hostname and redirect conditionally.
"Make everything as simple as possible, but no simpler" - A. Einstein.
Jim