我已经几个星期前开始的话题。 不过,我现在有一个新的问题,这是非常相似的老问题:.htaccess ?"一个问号&QUOT重写URL
我的目标是这个网址:
/ mysite的/组件/用户/?查看=登记
重写到这个新的URL:
的mysite / registration.html
我现在的的.htaccess
得到这个code:
的RewriteBase / mysite的
的RewriteCond%{QUERY_STRING} ^视图=(。*)$
重写规则^组件/用户/?$%1.HTML? [R = 301,L]
它的工作非常细。
但后来我发现,这个配置担心,开始喜欢这一切网址:
/ mysite的/组件/用户/?查看=
例如这个配置也将涉及这样一个网址:
/ mysite的/组件/用户/?查看=提醒
这是我不想要的东西。
我只希望这个URL重写:
本地主机/ mysite的/组件/用户/?查看=登记
解决方案
的RewriteBase / mysite的
的RewriteCond%{QUERY_STRING} ^视图=(注册)$ [NC]
重写规则^组件/用户/ $%1.HTML? [R = 301,L]
如果你想让它仅适用于报名工作
则可以指定,而不是一个包罗万象的正则表达式。
同时请记住,因为你有一个全球性的永久重定向了它,你可能需要清除浏览器缓存或使用不同的浏览器,即时看到的变化。
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
解决方案
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.