如何重写和重定向 URL

我有 URL:

http://domain.com/i.php?c=PT
我重写了它
http://domain.com/PT
成功地。 但是当我看到
http://domain.com/i.php?c=PT
, 它不会被重定向到
http://domain.com/PT
. 有没有办法重定向和重写?

我的 .htaccess:

RewriteEngine On
RewriteCond %{QUERY_STRING} ^c=([a-zA-Z][a-zA-Z])$
RewriteRule ^/index.php$ /%1%2? [R=301,L]
RewriteRule ^([a-zA-Z][a-zA-Z])$ i.php?c=$1$2 [NC,L]



更新 №1: 我想重定向 domain.com/i.php?c=PT -> domain.com/PT.

我没有文件 index.php.
已邀请:

快网

赞同来自:

我不确定你想要什么样的行为,我看不到 index.php 在您的查询中,但它处于配置中。 在任何情况下,它都覆盖了任何 URL 从形式

hostname/XX



hostname/i.php?c=XX

RewriteEngine On
RewriteRule ^/([a-zA-Z]{2})$ /i.php?c=$1 [R=301,NC,L]

用于反向翻译:

RewriteCond %{QUERY_STRING}  ^c=([a-zA-Z]{2})$
RewriteRule ^/i.php$ /%1? [R=301,NC,L]

你可以

调试

您的覆盖规则添加:

RewriteEngine On
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 3

要回复问题请先登录注册