使用 mod_rewrite 将现有文件重定向到不同的 url
我正在尝试使用 mod_rewrite 将现有文件重定向到不同的 URL。我正在使用以下内容,但没有效果。我已经尝试了几种不起作用的变体。
RewriteEngine on
AddHandler x-httpd-php .php3
# AddHandler x-httpd-php5 .php .php4
# This file exists, but this redirect doesn't work
RewriteRule ^show.php?id=review-1$ /review/1/super-baseball-2020/ [R=301,L]
它是否偶然与 url 参数有关?
I'm trying to use mod_rewrite to redirect an existing file to a different URL. I'm using the following and it has no effect. I've tried several variations of which don't work.
RewriteEngine on
AddHandler x-httpd-php .php3
# AddHandler x-httpd-php5 .php .php4
# This file exists, but this redirect doesn't work
RewriteRule ^show.php?id=review-1$ /review/1/super-baseball-2020/ [R=301,L]
Does it by chance have something to do with the url params?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
RewriteRule 中不能有查询字符串。 RewriteRule 仅匹配 URL 部分,这就是您的新规则不起作用的原因。您需要有一个单独的 RewriteCond 来匹配 QUERY 字符串。它应该像这样重写:
You cannot have query string in RewriteRule. RewriteRule matches only URL part that's why your new rule is not working. You need to have a separate RewriteCond to match QUERY string. It should be re-written like this: