.htaccess文件将忽略第一个规则
网址应为http://example.com/public_html/folder/file.php
# Rewrite all to public_html
RewriteCond %{REQUEST_URI} !php/
RewriteRule (.*) /public_html/$1
# URL: http://example.com/public_html/folder/file
# Hide/Add .php from/to URL
RewriteCond %{DOCUMENT_ROOT}/$1 !-d
RewriteCond %{REQUEST_FILENAME} !\.(.*)
RewriteCond %{REQUEST_URI} !php/
RewriteRule (.*) $1.php
# URL: http://example.com/folder/file.php
答案 0 :(得分:1)
在/Users/gus/sites/New/8888/goestav5/.htaccess
中这样保存:
RewriteEngine On
# ignore all php/ URIs
RewriteRule ^php/ - [L,NC]
# add .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+?)/?$ $1.php [L]
# rewrite every non-file, non-directory to public_html
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!public_html/)(.*)$ public_html/$1 [L,NC]