简体   繁体   中英

.htaccess redirecting to https excluding one path

I'm redirecting my hole website (WordPress) from HTTP to HTTPS, and I want to exclude one path from that.

That path is excluded from that rule, but for some reason it's being redirected to the home path ( http://mywebsite.com/excludedpath -> https://mywebsite.com/index.php ) instead of just not redirecting it. All other paths are redirected properly to HTTPS.

The .htaccess I'm using is:

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>

Am I missing something? Why is the excluded path redirected to the website's home page?

You can use RewriteCond to check if the request uri is starting with /excludedpath .

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !^[A-Z]{3,}\s/excludedpath/ [NC] 
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM