【问题标题】:Not Found when shortening URL缩短网址时找不到
【发布时间】:2014-08-24 14:46:37
【问题描述】:

所以我将article.php?id=10 缩短为article/10。这一切似乎都很好。但我几乎不知道它毁了我的其他 URL。所以对于http://localhost/forgot/,我必须去http://localhost/forgot/index 才能真正到达它。这是我正在使用的

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^article/([0-9]+)$ article.php?id=$1

RewriteRule ^([^\.]+)$ $1.php [NC,L]

我想去http://localhost/forgot/ 而不是http://localhost/forgot/index/ 有什么想法吗?

【问题讨论】:

    标签: php regex .htaccess url


    【解决方案1】:

    有这样的规则:

    Options -MultiViews
    DirectoryIndex index.php
    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L,QSA,NC]
    
    # rewrite from /dir/file/ to /dir/file.php
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
    RewriteRule ^(.+?)/?$ /$1.php [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 1970-01-01
      • 1970-01-01
      • 2018-12-04
      • 1970-01-01
      • 2013-02-19
      • 1970-01-01
      相关资源
      最近更新 更多