2016-01-10 52 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]