2016-01-10 51 views
2

我的.htaccess文件有问题。PHP .htaccess RewriteRule允许多种组合

在我的.htaccess规则,如果我把这个:

RewriteRule ^post/([^/]*)$ /the_post.php?id=$1 [L]

我就能够浏览的网址是这样的:
http://www.example.com/post/12

但如果我尝试:
http://www.example.com/post/12/

http://www.example.com/post/12/something-else-here

该页面未建立。

什么是正确的方式来允许任何可能的组合的网址?

  • http://www.example.com/post/12
  • http://www.example.com/post/12/
  • http://www.example.com/post/12/something-else-这里

谢谢你的时间!

回答

1

根据您当前的规则:

RewriteRule ^post/([^/]*)$ /the_post.php?id=$1 [L] 

你不能有任何/在您的网址post/后。 [^/]*表示除/以外的任何字符。

你可以试试这个规则:

RewriteRule ^post/([0-9]+) /the_post.php?id=$1 [L,QSA] 
+0

它works.Thanks! – Nano

0

您可以使用此规则,以取代您的规则:

RewriteRule ^post/([^/]+)(/[^/]*)?/?$ the_post.php?id=$1 [L,NC,QSA]