我将我的漏洞网站(WordPress)从HTTP重定向到HTTPS,我想从中排除一条路径。
该路径被排除在该规则之外,但出于某种原因,它被重定向到主路径(http://mywebsite.com/excludedpath - > https://mywebsite.com/index.php),而不是仅仅重定向它。所有其他路径都正确地重定向到HTTPS。
我使用的.htaccess是:
RewriteOptions inherit
Header set Access-Control-Allow-Origin "*"
# Block via User Agent
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} (libwww|EvilBot|ScumSucker|FakeAgent) [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) - [F,L]
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule ^((?!excludedpath).)*$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN GZIP
<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</IfModule>
# END GZIP
#Image Expires Tag Test
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpg "access plus 1 month"
ExpiresByType image/jpeg "access plus 1 month"
ExpiresByType image/gif "access plus 1 month"
ExpiresByType image/png "access plus 1 month"
</IfModule>
我错过了什么吗?为什么排除的路径会重定向到网站的主页?
答案 0 :(得分:0)
您可以使用RewriteCond
检查请求uri是否以/excludedpath
开头。
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/excludedpath/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]