重定向现有的文件,以不同的使用mod_rewrite的URL重定向、不同、文件、URL

由网友(旧情悲伤旧言虐心)分享简介:我试图使用mod_rewrite现有文件重定向到一个不同的URL。我使用的是下面的,它有没有效果。我试过几种变化,其中不工作。I'm trying to use mod_rewrite to redirect an existing file to a different URL. I'm using the fol...

我试图使用mod_rewrite现有文件重定向到一个不同的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]

一个偶然的机会是否有事可做的URL PARAMS?

Does it by chance have something to do with the url params?

推荐答案

您不能在重写规则的查询字符串。重写规则只匹配URL的一部分,这就是为什么你的新规则是行不通的。你需要有一个单独的RewriteCond匹配查询字符串。应该重新写成这样:

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:

# for external redirect from /shows.php?id=review-1 to /review/1/super-baseball-2020/
RewriteCond %{THE_REQUEST} ^GETs/shows.php?
RewriteCond %{QUERY_STRING} (?:^|&)id=([^-]*)-(.*)(?:&|$) [NC]
RewriteRule ^ /%1/%2/super-baseball-2020/? [R=301,L,NC]

# for internal redirect from /review/1/super-baseball-2020/ to /shows.php?id=review-1
RewriteRule ^([a-z0-9]+)/([0-9]+)/([a-z0-9-]+)?/?$ shows.php?id=$1-$2 [L,NC,QSA]
阅读全文

相关推荐

最新文章