【问题标题】:Only first RewriteRile working in .htaccess file只有第一个 RewriteRile 在 .htaccess 文件中工作
【发布时间】:2015-03-01 16:30:14
【问题描述】:

我的 htacces 文件中有 2 个重写规则,但只有第一个有效

删除 .php

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

将我的网址 blog-detailed.php?id=1 编辑为 blog/1

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^blog/([0-9]+)/?$ blog-detailed.php?id=$1

【问题讨论】:

    标签: regex apache .htaccess mod-rewrite


    【解决方案1】:

    按此顺序制定规则:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^blog/([0-9]+)/?$ blog-detailed.php?id=$1 [L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME}\.php -f
    RewriteRule ^(.*)$ $1.php [L]
    

    【讨论】:

      猜你喜欢
      • 2018-09-09
      • 2013-07-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-10
      • 1970-01-01
      • 1970-01-01
      • 2011-12-15
      相关资源
      最近更新 更多