缩短URL时找不到

时间:2014-08-24 14:46:38

标签: php regex .htaccess url

所以我将article.php?id=10缩短为article/10。这一切似乎都很好。但我几乎不知道它破坏了我的其他网址。因此,对于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 /任何想法?

1 个答案:

答案 0 :(得分: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]