问题
I just want 301 redirect rule for multiple query string to make it SEO friendly url.
Internal Url: www.example.com?p=54&p1=ABC XYZ&p2=XXX45767
and so on.
301 Redirect Url: www.example.com/54-ABC-XYZ-XXX45767?p=54&p1=ABC XYZ&p2=XXX45767
So, the redirect url must contain the old query parameters too.
回答1:
First step is to check the QUERY_STRING
for the parameters in question. If a match is found, then a redirect should occur.
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]
To make the redirect permanent and cached by browsers and search engines, change 302
to 301
.
来源:https://stackoverflow.com/questions/31230970/htaccess-301-redirect-rule-for-multiple-query-strings