2017-08-11 107 views
0

我知道这可能非常简单,但我已经通过几个链接,找不到我正在寻找的答案。htaccess重写规则 - url参数

我的URL:

www.website.org/shows/index.php?id=1

希望重写:

www.website.org/shows/id/index.php

我知道我需要使用.htaccess中的RewriteRule来处理Apache,我只是无法弄清楚如何让它匹配然后重写。提前致谢。

我的失败尝试:

RewriteRule ^/shows/index.php?id=([0-9])$ shows/$1/index.php 

回答

1

你重写规则应该是这样的:

RewriteCond %{QUERY_STRING} ^id=([0-9]*)$ 
RewriteRule ^shows/index\.php$ /shows/%1/index.php 

有一个很好的官方文档,解释了如何访问quesry刺在重写规则:https://simonecarletti.com/blog/2009/01/apache-query-string-redirects/

+0

非常感谢您的回答!并感谢你10倍的非常有用的链接!非常感谢!! –