带有URL参数的Htaccess-order


Htaccess with URL parameters - order

我有两个模式需要重定向。

www.example.com/tag/value to www.example.com/recipe-tag/value
www.example.com/?tag=value to www.example.com/recipe-tag/value

这是我当前的.htaccess

RewriteEngine On
RewriteBase /
RewriteRule ^tag/(.*) http://www.example.com/recipe-tag/$1 [R=301,L]
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

这适用于第一次重定向。我应该怎么做才能使第二个重定向工作?

您必须使用一个条件来检测查询字符串。试试看。

RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} tag=(.+)$
RewriteRule ^ http://www.example.com/recipe-tag/%1? [R=301,L]
RewriteRule ^tag/(.*) http://www.example.com/recipe-tag/$1 [R=301,L]
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

让我知道这对你来说是怎么回事。