.htaccess rewrite URL with a question mark “?” only for 1 specific URL

随声附和 提交于 2019-12-23 10:57:56

问题


I already started a topic some weeks ago. But I got now a new problem that is very similar to the old problem: .htaccess rewrite URL with a question mark "?"

My aim was this URL:

/mysite/component/users/?view=registration

Rewrite into this new URL:

mysite/registration.html

My current .htaccess got this code:

RewriteBase /mysite

RewriteCond %{QUERY_STRING} ^view=(.*)$
RewriteRule ^component/users/?$ %1.html? [R=301,L]

It worked very fine.

But then I noticed that this config concerns all URL that starts like this:

/mysite/component/users/?view=

For example this config would also concern an URL like this:

/mysite/component/users/?view=remind

This is what I don't want

I only want this URL rewritten:

localhost/mysite/component/users/?view=registration

回答1:


RewriteBase /mysite

RewriteCond %{QUERY_STRING} ^view=(registration)$ [NC]
RewriteRule ^component/users/$ %1.html? [R=301,L]

If you want it to work only for registration then you can specify that instead a catchall regex.

Also keep in mind that since you had it with a global permanent redirect you may need to clear your browser cache or use a different browser to instantly see the changes.



来源:https://stackoverflow.com/questions/18884082/htaccess-rewrite-url-with-a-question-mark-only-for-1-specific-url

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