Forum Moderators: phranque
Redirect any requests from www.domain1.com/* to www.domain2.com/*
[and] domain1.com/* to domain2.com/*
But to NOT redirect any subdomains ie sub.domain1.com
Thank you
[edited by: jdMorgan at 2:05 am (utc) on Jan. 7, 2009]
[edit reason] de-linked [/edit]
at domain.com/.htaccess
Options +Indexes
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^whatever/[^.]+)$ [domain.com...] [R=301,L]
or
RewriteRule ^index.htm$ [domain.com...] [R=301,L]
The second example only changes one URL.
[^.]+) and $1 work the same way here as in mod_rewrite, so you can easily change a lot of URLs with one line. The only change with redirects and mod_rewrite is the R=301 (Redirect 301).
<snip>
[edited by: jdMorgan at 1:28 pm (utc) on Jan. 7, 2009]
[edit reason] No ULRs, please. See Terms of Service and Charter. [/edit]
At domain1.com/.htaccess :
Options +FollowSymlinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com
RewriteRule (.*) http://www.domain2.com/$1 [R=301,L]
While it is true that code could (and should) be installed at domain2.com to take care of this duplication problem, the result of doing only that in this situation, would be two 'stacked' or 'chained' 301 redirects, and search engines are not so likely to pass PageRank/Link-popularity through two consecutive redirects as through one.
That is, if domain1 is redirected to domain2 and www.domain1 is redirected to www.domain2, but domain2 is not redirected to www.domain2.com, then duplicate content still appears at domain2 and www.domain2. If a redirect is used at domain2 to fix this, then a request for domain1 would result in a redirect to domain2, and that would result in a redirect to www.domain2 -- Two redirects in a row.
Best practices dictate that any given unique content should be accessible at one and only one URL on the Web; Requests for any and all variations on that URL should be redirected to that single canonical URL.
This would include the following, at least:
example.com/
example.com./ (FQDN - Fully Qualified Domain Name)
example.com:80/ (appended port number)
example.com.:80/ (both)
example.com/index.html (redirect this to example.com/)
example.com/page.html?bogus-query-string or example.com/?bogus-query-string
example.com/&malformed-query-string (missing the "?" query demarcation token)
eXaMpLe.cOm (mis-cased)
example.com/mIs-CaSeD-URL-path
example.com/url-path?name1=value1&name2=value2 versus example.com/url-path?name2=value2&name1=value1 (parameter order)
http vs. https protocol
In all cases, the request for the non-canonical URL should be 301-redirected to the canonical URL or should result in a 404-Not Found server response.
Jim
[edit] Fixed typo in RewriteCond: {} must be () [/edit]
[edited by: jdMorgan at 8:24 pm (utc) on Jan. 7, 2009]