我还有另一个域名301重定向问题。
.htaccess文件如下。当我执行完整的域重定向时,由于计划不周,域重定向应该在我目前在网站上重定向之前或之后落下。
长话短说,我有一个宽松的网站,我将其导出并从头开始重建(这是一场噩梦)。现在我只是转向更加SEO友好的域名。当我把它移出时,我也决定更改许多页面的URL,所以我最初有很多404和页面没有被索引。
的.htaccess
DirectoryIndex index.php index.php3 messagebrd.pl index.html index.htm
ErrorDocument 403 /403.html
ErrorDocument 404 /404.html
Header append Vary User-Agent
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-old.com
RewriteRule ^(.*)$ http://www.example-old.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^2/(.*)
RewriteRule /index.html [R=301,L]
RewriteCond %{HTTP_HOST} ^1/(.*)
RewriteRule /index.html [R=301,L]
RewriteBase /
RewriteCond %{HTTP_HOST} !example-new.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [L,R=301]}
答案 0 :(得分:1)
should the domain redirect fall before or after the redirects I currently have
The "full domain redirect", and by that I assume you mean the redirect from ng-include
to example-old.com
, should be at the top of your redirects.
I assume example-new.com
and example-old.com
currently resolve to the same site - the new site. In which case you can combine your domain and example-new.com
canonical redirects. For example, replace the following:
www
RewriteCond %{HTTP_HOST} ^example-old.com
RewriteRule ^(.*)$ http://www.example-old.com/$1 [R=301,L]
RewriteBase /
RewriteCond %{HTTP_HOST} !example-new.com$ [NC]
With this:
RewriteRule ^(.*)$ http://www.example-new.com/$1 [L,R=301]}
This should go at the top of your mod_rewrite directives, immediately after the RewriteCond %{HTTP_HOST} !=www.example-new.com [NC]
RewriteRule (.*) http://www.example-new.com/$1 [R=301,L]
directive. This basically says, if the requested host is not RewriteEngine On
then redirect to www.example-new.com
. So, this will catch www.example-new.com
, example-old.com
and www.example-old.com
and anything else that isn't example-new.com
!
Incidentally, you had an erroneous www.example-new.com
(curly brace) at the end of the }
and the RewriteRule
directive is not required here.
RewriteBase
RewriteCond %{HTTP_HOST} ^2/(.*)
RewriteRule /index.html [R=301,L]
RewriteCond %{HTTP_HOST} ^1/(.*)
These two rules are invalid and don't actually do anything - or at least they don't do what they should be doing! The substitution (target URL) is missing from both the RewriteRule /index.html [R=301,L]
directives. But the RewriteRule
directives also don't make sense and will never match anyway.
Also, my sites are indexing two different pages for root and
RewriteCond
.
Presumably you don't want the /index.html
indexed and are referencing only /index.html
in your URLs? You can try adding the following redirect following the redirect above to help resolve this:
/
This obviously assumes that RewriteCond %{THE_REQUEST} /index\.html
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
is your only index.html
(the file that Apache tries to return when you request a directory).
DirectoryIndex
If you only have DirectoryIndex index.php index.php3 messagebrd.pl index.html index.htm
index documents then you don't need to specify all the others that are not used. Incidentally, this list of files are in order to preference. Apache will first look for index.html
, then index.php
, etc.