【问题标题】:PHP .htaccess RewriteRule allow multiple combinationPHP .htaccess RewriteRule 允许多重组合
【发布时间】:2016-01-10 17:37:53
【问题描述】:

我的 .htaccess 文件有问题。

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

重写规则 ^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

该页面未创建。

允许任何可能的 url 组合的正确方法是什么?

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

感谢您的宝贵时间!

【问题讨论】:

    标签: php apache .htaccess mod-rewrite


    【解决方案1】:

    根据您当前的规则:

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

    您的网址中的post/ 后面不能有任何/[^/]* 表示除/ 之外的任何字符。

    你可以试试这个规则:

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

    【讨论】:

      【解决方案2】:

      您可以使用此规则替换您的规则:

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

      【讨论】:

        猜你喜欢
        • 2014-12-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2022-12-04
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多