Apache Htaccess - 重写规则冲突和/或订单

时间:2016-01-15 21:33:21

标签: php apache .htaccess mod-rewrite url-rewriting

我经常不使用.htaccess,但最近我必须设置一个本地网络服务器,最后我得到了以下重写规则:

# Settings: General
Options +FollowSymlinks
RewriteEngine On
RewriteBase /

# Settings: Protocol
RewriteRule ^ - [env=PROTO]
RewriteCond %{HTTPS} on
RewriteRule ^ - [env=PROTO:s]

# Remove WWW (https://www.example.com/ -> https://example.com/)
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http%{ENV:PROTO}://%1%{REQUEST_URI} [R=301,L]

# Versioning (main.20150826.css -> main.css)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.(\d+)\.(?:bmp|css|cur|gif|ico|jp(?:eg?|g)|js|png|svgz?|tiff?|webp)$ $1.$3 [L]

# Forbidden/Missing Resources (403 if directory/file starts with '.')
RewriteRule (?:^|/)\. - [F]

# Missing Resources (403 if file/directory not found)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ - [F,L]

# Hotlinking Prevention
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.(?:bmp|cur|gif|ico|jp(?:eg?|g)|png|svgz?|tiff?|webp)$ [NC]
RewriteCond %{HTTP_REFERER} !^https?://([^.]+\.)?domain\.tld [NC]
RewriteRule \.(?:bmp|cur|gif|ico|jp(?:eg?|g)|png|svgz?|tiff?|webp)$ - [NC,F,L]

由于我不是真正的专家,我想知道他们是否被安排在正确的执行顺序中,以及是否存在与其中一些人的冲突问题!

非常感谢提前!

0 个答案:

没有答案