.htaccess 用问号“?"重写 URL; [英] .htaccess rewrite URL with a question mark "?"

查看:29
本文介绍了.htaccess 用问号“?"重写 URL;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的目标是这个网址:

component/users/?view=registration

致:

registration.html

.htaccess 位于网站的 mysite 文件夹中.

the .htaccess is in the folder mysite of the website.

我试过这个:

RewriteBase /mysite
RewriteRule ^component/users/?view=registration$ registration.html$ [R=301,L]

但我不工作...

当我尝试这个时:

RewriteRule ^component/users/_view=registration$ registration.html$ [R=301,L]

效果很好.

那么我该如何用问号解决这个问题.我已经读过 它不是 URL 的一部分(其附加).我已经读到我必须使用诸如查询字符串之类的东西,但我并没有真正理解语法.

So how can i fix this problem with the question mark. I already read thats it is not a part of the URL (its appended). I have read that i have to use something like querystring, but i didn't really understand the syntax.

也许有人可以写出这个问题的解决方案?会很棒=)

Maybe someone could write the solution of this problem? Would be awesome =)

推荐答案

需要使用%{QUERY_STRING}来捕获查询字符串数据:

You need to use %{QUERY_STRING} to capture the query string data:

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

如果路径 component/users 匹配,上述规则/条件将采用查询字符串视图的值并使用它来形成您的重定向.

The above rule/condition will take the value of the query string view and use it to form your redirect if the path component/users matches.

这篇关于.htaccess 用问号“?"重写 URL;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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