重写URL时禁止访问

时间:2015-11-04 00:22:08

标签: apache .htaccess xampp

我使用以下.htaccess代码来填写我网页的php扩展程序:

RewriteEngine On
RewriteOptions inherit
Options +FollowSymlinks
Options -Multiviews
## hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ %{REQUEST_FILENAME}\.php [NC,L]

我可以转到localhost:80/site/page.php,但当我尝试去localhost:8/site/page时,XAMPP会给我一个"禁止访问"错误。这里发生了什么,我做错了什么?

1 个答案:

答案 0 :(得分:0)

以这种方式尝试你的规则。

Options +FollowSymlinks -Multiviews
## hide .php extension
## To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ $1.php [NC,L]