htaccess没有给出正确的值

时间:2013-04-08 01:19:05

标签: apache .htaccess mod-rewrite

我想让这个工作,但我遇到了问题。当我转到http://localhost/test/demo/并回显p的值时,我得到demo。但当我转到http://localhost/test/demo/moretext/ p的值是index.php/moretext时,为什么要这样做呢? .htaccess文件位于test目录中。

Options +FollowSymLinks
RewriteEngine On
RewriteBase /test/

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/(.+?)/$ index.php?p=$1&file=$2
RewriteRule ^(.+?)/$ index.php?p=$1

1 个答案:

答案 0 :(得分:1)

您可以在/test目录中的一个.htaccess文件中尝试此操作:

Options +FollowSymlinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_URI}  !index\.php       [NC]
RewriteCond %{REQUEST_URI}  ^/test/([^/]+)/([^/]+)/?$ [NC]
RewriteRule .*  /test/index.php?p=%1&file=%2  [L]

RewriteCond %{REQUEST_URI}  !index\.php       [NC]
RewriteCond %{REQUEST_URI}  ^/test/([^/]+)/?$ [NC]
RewriteRule .*    /test/index.php?p=%1  [L]