简体   繁体   中英

Force HTTPS on certain directories and force HTTP on all others using .htaccess

I found a potential solution to this question already here: Force HTTPS on certain URLs and force HTTP for all others but this did not redirect users as expected.

I am trying to get everyone who loads any file within http://mydomain.com/registration/ or its subdirectories to be directed to https://mydomain.com/registration/ (with or without www., I don't care) but for all files not within that directory to be forced to use HTTP.

Adapting the solution above by simply replacing 'my' with 'registration' saw no change for non-/registration/ URLs and for any /registration/ URLs the user ended up in a redirect loop.

I think it may have something to do with what is already in my .htaccess file. I need the new code and my existing code to work concurrently and that's where I really need help:

<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^runners/([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)/([a-z0-9\-]+)$ index.php?p=runners&sortby=$1&dir=$2&page=$3&perpage=$4 [L]
RewriteRule ^([a-z0-9\-]+)$ index.php?p=$1 [L]
</IfModule>

Try this:

RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_URI} ^/registration [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,QSA,L]

This should be pasted right below RewriteBase / line.

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