【发布时间】:2020-02-07 17:11:52
【问题描述】:
我的 .htaccess 文件有重定向和重写代码。除了一页,一切都很好。我需要将https://example.com/shopping/ceylon-cinnamon-c-62.html 和http://example.com/shopping/index.php?cPath=62 重定向到https://example.com/ceylon-cinnamon-c-2_19.html 我已经尝试了下面NONE OF THESE WORK 下面的四行(一次一个),但重定向永远不会起作用。结果网址为https://example.com/c-62.html。谁能指出问题或如何测试它?
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
# NONE OF THESE WORK
Redirect 301 /shopping/ceylon-cinnamon-c-62.html https://example.com/index.php?cPath=2_19
Redirect 301 /shopping/index.php?cPath=62 https://example.com/index.php?cPath=2_19
RewriteRule ^(.*?)shopping/ceylon-cinnamon-c-62.html$ https://example.com/index.php?cPath=2_19 [R=301,L,NC]
RewriteRule ^(.*?)shopping/index.php?cPath=62$ https://example.com/index.php?cPath=2_19 [R=301,L,NC]
# THESE ALL WORK
RewriteRule ^shopping/(.*)$ /$1 [R=301,NC,L]
#redirect index.php to root
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ https://example.com/ [R=301,L]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING}
【问题讨论】:
-
您无法使用
Redirect或RewriteRule匹配查询字符串。使用RewriteCond %{QUERY_STRING}
标签: .htaccess mod-rewrite