htaccess 301多个查询字符串的重定向规则 [英] htaccess 301 redirect rule for multiple query strings
问题描述
我只想对多个查询字符串使用301重定向规则以使其成为SEO友好的网址。
I just want 301 redirect rule for multiple query string to make it SEO friendly url.
内部网址: www.example.com? p = 54& p1 = ABC XYZ& p2 = XXX45767
,依此类推。
Internal Url: www.example.com?p=54&p1=ABC XYZ&p2=XXX45767
and so on.
301重定向网址: www。 example.com/54-ABC-XYZ-XXX45767?p=54&p1=ABC XYZ& p2 = XXX45767
301 Redirect Url: www.example.com/54-ABC-XYZ-XXX45767?p=54&p1=ABC XYZ&p2=XXX45767
因此,重定向url也必须包含旧的查询参数。
So, the redirect url must contain the old query parameters too.
推荐答案
第一步是检查 QUERY_STRING
表示相关参数。如果找到匹配项,则应该进行重定向。
First step is to check the QUERY_STRING
for the parameters in question. If a match is found, then a redirect should occur.
您可以在 /。htaccess
中使用以下内容文件:
You can use the following in your /.htaccess
file:
RewriteEngine On
# Check the query string and capture parts
RewriteCond %{QUERY_STRING} ^p=([^&]+)&p1=([^&]+)&p2=([^&]+)$
# If at the root of the domain, redirect
RewriteRule ^$ /%1-%2-%3 [R=302,L]
要使重定向永久化并由浏览器和搜索引擎缓存,请将 302
更改为 301
。
To make the redirect permanent and cached by browsers and search engines, change 302
to 301
.
这篇关于htaccess 301多个查询字符串的重定向规则的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!