delato468 delato468 - 1 year ago 63
Apache Configuration Question

.htaccess different RewriteRule for child of directory

In my shop i have the problem, that SSL doesn´t work. So i used RewriteRule for force running SSL, but the problem is the admin area doesn´t work like that.(unknown resources load from ...)

For this reason i have to disable this RewriteRule all time if i would change something in the admin area.

It exist a possibility to except the admin area from RewriteRule ?

RewriteBase /shop/
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://domain/shop/$1 [R=301,L]

In the admin area i get with:

I tried something like that after the Rule above but it doesn´t work:

RewriteBase /shop/admin/
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) http://domain/shop/admin/$1 [R=301,L]

Answer Source

Inside /shop/.htaccess use these 2 rules at the top:

RewriteEngine On
RewriteBase /shop/

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/admin/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /admin/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [NE,R=301,L]