【问题标题】:.htaccess rewrite rule not working as expected.htaccess 重写规则未按预期工作
【发布时间】:2016-01-20 15:17:54
【问题描述】:

我有一个可点击的文章列表,href 是:/article/article-name

我希望使用 htaccess 文件重定向到 /article/article.php?id = 文章名称

并显示文章/文章名称

我当前的 htaccess 文件是:

RewriteEngine on
RewriteRule ^/(.+)/?$ ./article/article.php?id=$1 [L]

但是这不起作用。

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite


    【解决方案1】:

    在您的 /article/ 目录中试试这个 .htaccess:

    Options -MultiViews
    RewriteEngine on
    RewriteBase /article/
    
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([\w-]+)/?$ article.php?id=$1 [L,QSA]
    

    【讨论】:

      【解决方案2】:

      我的看法

      RewriteEngine on
      RewriteBase /
      RewriteRule ^article/([a-zA-Z0-9\-]+)$ article/article.php?id=$1 [L]
      

      【讨论】:

        猜你喜欢
        • 2015-02-03
        • 2013-08-11
        • 2019-03-15
        • 2020-01-12
        • 2016-06-10
        • 1970-01-01
        • 2018-08-12
        • 2013-07-24
        • 1970-01-01
        相关资源
        最近更新 更多