我无法使用 .htaccess 文件将旧站点 URL 重定向到新位置。条件似乎不匹配。我确信我只是做了一些愚蠢的事情,但我不知道是什么原因。我在这里包含了整个重写部分,以防其他部分导致问题,但我认为问题出在“重定向旧站点 URL”部分。
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
############################################
## force www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
############################################
## force SSL
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
############################################
## redirect old site URLs
RewriteCond %{REQUEST_URI} ^/Products\.aspx\?pid=3 [NC,OR]
RewriteCond %{REQUEST_URI} ^/contactus\.aspx [NC,OR]
RewriteCond %{REQUEST_URI} ^/tipsandadviceinstallation\.aspx [NC,OR]
RewriteCond %{REQUEST_URI} ^/index\.aspx [NC]
RewriteRule .* https://%{HTTP_HOST}/ [L,R=301]
RewriteCond %{REQUEST_URI} ^/PdfFiles/Cattle%20Floor%20Fitting%20Guidelines\.pdf [NC,OR]
RewriteCond %{REQUEST_URI} ^/Products\.aspx\?pid=41 [NC]
RewriteRule .* https://%{HTTP_HOST}/flooring/engineered-wood\.html\?manufacturer=4 [L,R=301]
RewriteCond %{REQUEST_URI} ^/Products\.aspx\?pid=812 [NC]
RewriteRule .* https://%{HTTP_HOST}/doors/internal.html?manufacturer=131 [L,R=301]
############################################
## workaround for HTTP authorization
## in CGI environment
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
############################################
## always send 404 on missing files in these folders
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
############################################
## never rewrite for existing files, directories and links
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
############################################
## rewrite everything else to index.php
RewriteRule .* index.php [L]
所有其他重写规则都有效。只有那部分有效。很无聊
Redirect 301 /Products.aspx?pid=812 https://www.flooringanddoors.co.uk/doors/internal.html?manufacturer=131
也可以工作,但我想要不区分大小写的匹配,而且我没有办法编写匹配所需的行数。
答案1
事实证明 %{REQUEST_URI} 也不包含查询字符串。这意味着我的匹配检查/Products\.aspx\?pid=812
缺少问号之后(包括问号)的所有内容。正确的规则是:
############################################
## redirect old site URLs
RewriteCond %{REQUEST_URI}?%{QUERY_STRING} ^/Products\.aspx\?pid=3 [NC,OR]
RewriteCond %{REQUEST_URI} ^/contactus\.aspx [NC,OR]
RewriteCond %{REQUEST_URI} ^/tipsandadviceinstallation\.aspx [NC,OR]
RewriteCond %{REQUEST_URI} ^/index\.aspx [NC]
RewriteRule .* https://%{HTTP_HOST}/? [L,R=301]
## The ? at the end of the rule here strips the Query_string from the first condition. Otherwise we would end up at the URL https://%{HTTP_HOST}/?pid=3
RewriteCond %{REQUEST_URI} ^/PdfFiles/Cattle\ Floor\ Fitting\ Guidelines\.pdf [NC,OR]
RewriteCond %{REQUEST_URI}?%{QUERY_STRING} ^/Products\.aspx\?pid=41 [NC]
RewriteRule .* https://%{HTTP_HOST}/flooring/engineered-wood.html?manufacturer=4 [L,R=301]
## The \<space> are used to match the %20
RewriteCond %{REQUEST_URI}?%{QUERY_STRING} ^/Products\.aspx\?pid=812 [NC]
RewriteRule .* https://%{HTTP_HOST}/doors/internal.html?manufacturer=131 [L,R=301]