我遇到的问题是某些重定向无法在网址末尾没有/
的情况下工作。此外,有时我会有重叠的重定向重写以下重定向。
Options -MultiViews
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}/$1\.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
ErrorDocument 404 /404.php
RewriteRule ^(.*)launch/$ /$1products/ [R=301,L]
RewriteRule ^(.*)solutions/$ /$1products/ [R=301,L]
示例:
当我在没有最后/launch
的情况下搜索/
时,我最终会在我的404页面上搜索。
RewriteRule ^(.*)products/overview/heartbeat/$ /$1products/heartbeat/ [R=301,L]
RewriteRule ^(.*)heartbeat/$ /$1products/heartbeat/ [R=301,L]
RewriteRule ^(.*)heartbeat-beta/$ /$1products/heartbeat-beta/ [R=301,L]
示例:
当我搜索/heartbeat-beta/
并期望得到/products/heartbeat-beta/
时,我的结果是:
/products/products/products/products/products/products/products/products/products/products/products/products/products/products/products/products/heartbeat-beta/
答案 0 :(得分:1)
您的重写规则序列不正确有一些可疑的正则表达式模式。按顺序排列:
RewriteRule ^(heartbeat(?:-beta)?)/?$ /products/$1/ [R=301,L,NC]
RewriteRule ^products/overview/(heartbeat)/?$ /products/$1/ [R=301,L,NC]
PS:要使用尾随斜杠可选,请使用正则表达式模式中的/?$
。