mod_rewrite - old parameter name to new name

戏子无情 提交于 2019-12-11 06:10:03

问题


Hi all I need a bit of getting a redirect working in mod_rewrite.

I need to redirect the following

http://mysite.com/dictionary/find?word=test

to

http://mysite.com/dictionary/find?w=test

I'm sure the solution is trivial enough but my knowledge of mod_rewrite and regular expressions is quite limited and I haven't been able to work out. This is what I have attempted so far to no avail.

RewriteCond %{QUERY_STRING} word= [NC]
RewriteRule ^/(.*)word=(\w+)/$ /w=$1 [L]

Any help would be much appreciated. Thanks.


回答1:


This should be sufficient for you...

RewriteRule (?|&)word=(\w+) $1w=$2

this will replace it even if combined with other parameters.Your attempt to only process the querystring is interesting, I have never used that and cannot answer to if it's possible.

As a sidenote, turn on:

RewriteLog "/var/log/apache2/rewrite.log"
RewriteLogLevel 2

for more useful feedback.




回答2:


Try this:

RewriteCond %{QUERY_STRING} ^(([^&]*&)*)word=(.*)
RewriteRule ^dictionary/find$ $0?%1w=%3 [R=301,L]


来源:https://stackoverflow.com/questions/569600/mod-rewrite-old-parameter-name-to-new-name

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