我想让这个工作,但我遇到了问题。当我转到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
答案 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]