我无法得到profile.php?username =因某些原因而离开。我在另一个文件夹中做了完全相同的事情,它正在工作,但不能在这个文件夹上工作,我没有看到我的错误。 另一个问题,我希望我的页面目录中的文件显示如下:localhost / test_a / filename(虽然真正的位置是localhost / test_a / pages / filename)但我不知道如何在内部重定向到它
RewriteEngine On
RewriteBase /
# remove /index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ %1 [R=301,L]
# externally redirect /dir/foo to /foo
RewriteCond %{THE_REQUEST} pages/
RewriteRule pages/(.*)$ test_a/$1 [L,NC,R]
# internally forward /foo to /dir/foo
--------------------------------------------------------------what goes here?
# externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
# internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ test_a/$1.php [L]
# Remove long profile url to simple 'profile/username'
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^profile/(.*)$ test_a/profile.php?username=$1
-------------------------------------------------------why is this not working?
#Deny access to htaccess
<files .htaccess>
order allow,deny
deny from all
</files>
答案 0 :(得分:0)
尝试关闭多视图。在某些安装中,打开了多视图,告诉mod_negotiation尝试“猜测”请求文件名。在这种情况下,/profile/asdasds
被猜测为/profile.php/asdasds
,这将完全绕过您的mod_rewrite规则。
所以将它添加到顶部:
Options -Multiviews
至于第一个问题,试试这个:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/test_a/pages/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/test_a/pages/$1 -d
RewriteRule ^(.*)$ test_a/pages/$1 [L]