具有 URL 个参数的 Htaccess - 顺序

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/ [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/ [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

告诉我这对你有用。