htaccess的重写URL一个问号“?”只为1特定的网址 [英] .htaccess rewrite URL with a question mark “?” only for 1 specific URL

查看:127
本文介绍了htaccess的重写URL一个问号“?”只为1特定的网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经几个星期前开始的话题。 不过,我现在有一个新的问题,这是非常相似的老问题:<一href="http://stackoverflow.com/questions/18543194/htaccess-rewrite-url-with-a-question-mark">.htaccess ?&QUOT;一个问号&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.

这篇关于htaccess的重写URL一个问号“?”只为1特定的网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆