2013-08-31 44 views
8

我的目标是这个网址:.htaccess用问号“?”重写URL

component/users/?view=registration 

要:

registration.html 

.htaccess是在网站的文件夹mysite的。

我想这:

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

但我不工作...

当我试试这个:

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

它工作得很好。

那么我该如何解决这个问题与问号。我已经读过它,它不是URL的一部分(附加)。我已经读过,我必须使用querystring之类的东西,但我并不真正了解语法。

也许有人可以写这个问题的解决方案?将是真棒=)

回答

21

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

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

以上规则/病情会获取查询字符串视图的值,并在路径component/users匹配时使用它来形成重定向。

+1

感谢您的答案,但它不工作。 ?鉴于=注册 当我键入: 的http://本地主机/ mysite的/组件/用户/图=注册 你有一个想法如何,可以去掉这个 – Bardock

+1

真棒? “视图=注册?”?! !谢谢兄弟,它现在有效:D – Bardock

-3
RewriteRule ^component/users/\?view=registration$ registration.html$ [R=301,L] 

你需要一个\因为?是正则表达式的一部分。使用它作为一个字符串ü需要用\

Linktip逃吧:http://ole.michelsen.dk/tools/regex.html

+4

不工作。它仍然重定向到本地主机/ mysite /组件/用户/?查看=注册:(: – Bardock