.htaccess redirect query string value to another key

人走茶凉 提交于 2020-01-16 14:17:10

问题


What i'm trying to do is rewrite the following pattern

http://example.org/path?articleid=5657

to this pattern:

http://example.org/path?p=5657

Essentially it comes down to changing the key to the url parameter, i have searched extensively with no clear example of how to do this exact thing using only htaccess rewrite rules.

i've tried this general approach with no luck

RewriteCond %{QUERY_STRING} ^articleid=([0-9]*)$ 
RewriteRule ^articleid=([0-9]*)$ /?p=$1 [R=301,L] 

回答1:


You can't match against the query string in the pattern of a rule, you need to match against the URI:

RewriteCond %{QUERY_STRING} ^articleid=([0-9]*)$ 
RewriteRule ^path$ /path?p=$1 [R=301,L] 


来源:https://stackoverflow.com/questions/18281229/htaccess-redirect-query-string-value-to-another-key

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