Dreamsickle
Dreamsickle

Reputation: 13

Redirect *example.com/* to https://example.com/*

I have an SSL certificate without "www" in front of my URL and I'm experiencing issues with Javascript's same-origin policy when users switch from http to https.

I would like to know how (what to type in .htaccess?) to redirect everything (http://www.example.com, http://example.com, and https://www.example.com) to https://example.com.

Also, I'd like for anything typed in after my URL (*example.com/*) to also redirect with https before the typed URL. (https://example.com/[whatever was typed]).

Thanks!

Upvotes: 1

Views: 470

Answers (1)

anubhava
anubhava

Reputation: 785541

put this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [NE,R=301,L]

Upvotes: 1

Related Questions