我最近修改了.htaccess文件的重定向。原因是因为我旧文件的指向特定页面的单个RedirectPermanent
链接无法正常工作。这是因为以前我将通配符代码放在顶部。唯一起作用的是我对此的主要重定向。
使用新代码,我尝试将RedirectPermanent
代码放在顶部。现在,什么都没有重定向。转到该网站时,我看到“索引为”页面(请参见下面的img)。
有人看不到我的新代码在做什么,这使它不起作用吗?
最新-不重定向
RewriteEngine On
# These redirects must execute first,
# there are url changes on destination server
RedirectPermanent /about-us.html https://newdomain.com/about
RedirectPermanent /about-us/t-slotted-aluminum-profiles.html https://newdomain.com/profile
RedirectPermanent /about-us/t-slot-nuts-fasteners.html https://newdomain.com/components
RedirectPermanent /about-us/customer-service.html https://newdomain.com/about
# Now that there are no more url changes,
# Wildcard everything else to new domain
RewriteCond %{HTTP_HOST} ^oldDomain.com$
RewriteRule (.*) https:/newdomain.com/$1 [R=301,L]
以前的代码
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?oldDomain\.com$ [NC]
RewriteCond %{THE_REQUEST} !/administrator [NC]
RedirectPermanent /about-us.html https://newDomain.com/about
RedirectPermanent /about-us/t-slotted-aluminum-profiles.html https://newDomain.com/profile
RedirectPermanent /about-us/t-slot-nuts-fasteners.html https://newDomain.com/components
RedirectPermanent /about-us/customer-service.html https://newDomain.com/about
RewriteRule ^ https://newDomain.com%{REQUEST_URI} [L,R=301,NE]
答案 0 :(得分:0)
您似乎丢失了一些东西。试试这个
RewriteEngine On
# These redirects must execute first,
# there are url changes on destination server
RedirectPermanent /about-us.html https://newdomain.com/about
RedirectPermanent /about-us/t-slotted-aluminum-profiles.html https://newdomain.com/profile
RedirectPermanent /about-us/t-slot-nuts-fasteners.html https://newdomain.com/components
RedirectPermanent /about-us/customer-service.html https://newdomain.com/about
# Now that there are no more url changes,
# Wildcard everything else to new domain
RewriteCond %{HTTP_HOST} !^newDomain\.com
RewriteRule (.*) https://newDomain.com/$1 [R=301,L]