htaccess的重写URL一个问号"?"重写、问号、htaccess、QUOT

2023-09-02 09:39:12 作者:五个字的文艺

我的目标是这个网址:

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]

但我不工作...

But i doesnt work...

当我尝试这样的:

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

它工作得很好。

it works very well.

那么,如何解决这个问题的问号。我已经读过这就是它是不是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]

以上规则/条件将查询字符串观点的价值,并用它来形成你的重定向,如果路径组件/用户相匹配。