Gideon
Gideon

Reputation: 1886

Use directives in .htaccess to selectively redirect http traffic to https (apache)

I currently have a two mod_rewrite rules set up in my .htaccess file

rewriteCond %{HTTP_HOST} ^mysite.org [NC]
rewriteRule ^(.*)$ https://www.mysite.org/$1 [R=301,L]

rewriteCond %{SERVER_PORT} =80
rewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI}

The former being to redirect any traffic from mysite.org -> https://www.mysite.org, the latter picking up anything on port 80 (http) and send it to https.

But the admin control panel for my CMS is not accessible via https so I need to be able to access anything with the sub-domain mysite.org/admin via http.

Is this possible?

Upvotes: 1

Views: 135

Answers (1)

anubhava
anubhava

Reputation: 785108

You can create an exception for admin:

rewriteCond %{HTTP_HOST} ^mysite.org [NC]
rewriteRule ^(.*)$ https://www.mysite.org/$1 [R=301,L]

rewriteCond %{SERVER_PORT} =80
rewriteRule ^((?!admin).*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Upvotes: 1

Related Questions