htaccess 301 redirect rule for multiple query strings

二次信任 提交于 2019-12-25 00:39:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!