Htaccess redirect all plus exception

Hi,

I’ve got a very basic htaccess file that redirects all site traffic to a https version of a site:

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.website.com/$1 [R,L]

However, is it possible to add a rule to the htaccess that if the site is accessed via its dedicated IP it doesn’t redirect to the https and can be used via the IP without the SSL?

I’ve no clue where to start with this.

Hi Gen,

Good question! The venerable old {HTTP_HOST} is the appropriate one to use. Simply add an additional RewriteCond:

RewriteCond %{HTTP_HOST} example\.com$ [NC]

NC is the No Case flag which is necessary because the {HTTP_HOST} variable is NOT case sensitive.

This will be ANDed with your server port condition and the RewriteRule to match and redirect.

Regards,

DK

That’s worked perfectly, exactly as expected. Thank you very much for your help!

Gen,

You’re very welcome.

Regards,

DK

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.