htaccess不会重写所有规则

时间:2018-08-20 11:17:01

标签: .htaccess

.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

1 个答案:

答案 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]