I'm trying to force HTTPS for every request on my portfolio and also remove the WWW from the url. I've managed to remove the WWW from requests however when I try force HTTPS I'm given an error of "Too many redirects"
This is my htaccess file:
# remove www. from HTTPS requests
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(patrickwhitehouse\.pw)$ [NC]
RewriteRule .* https://%1/$0 [R,L]
# redirect HTTP requests to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(patrickwhitehouse\.pw)$ [NC]
RewriteRule .* https://%1/$0 [R,L]
If I manually put https://myurl.com, it works however when I visit another page, the HTTPS goes back to HTTP.
Your code is redirecting WWW. not removing it. Here is a code I've been using for the same issue.
### WWW & HTTPS
#Remove WWW
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
#Ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Related
For a long time we have had our site running without www in front, but we have recently been forced to make a change.
We recently changed from domainhere.com to www.domainhere.com. We already had a redirect from http to https, but need to change the redirect from https://domainhere.com to https://www.domainhere.com.
We used this code. How do we make it still redirect to HTTPS but with www in front?
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.skarpeknive.dk/$1 [R,L]
We found this on Stackoverflow, but it doesn't seem to work. The site bugs on domainhere.com then
#First rewrite any request to the wrong domain to use the correct one (here www.)
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
#Now, rewrite to HTTPS:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Maybe there is proxy issue so,try this :
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Note: clear browser cache then test
I have a multistore setup on magento with multiple domains.
But I want just one specific store/domain to have https, and redirect all non https urls for that domain to https. Including the whole path.
For example all urls in this list to https://www.
Source urls:
http:// webwinkel.nl/willekeurige-categorienaam
www. webwinkel.nl/willekeurige-categorienaam
http:// www.webwinkel.nl/willekeurige-categorienaam
https:// webwinkel.nl/willekeurige-categorienaam
Target url:
https:// www.webwinkel.nl/willekeurige-categorienaam
I use this for a single store, and in that case it works perfect.
RewriteCond %{HTTPS} off
# First rewrite to HTTPS:
# Don't put www. here. If it is already there it will be included, if not
# the subsequent rule will catch it.
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Now, rewrite any request to the wrong domain to use www.
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But for a multistore this doesn't work, because it will redirect every store domain to https, but I want https only for one specific store.
Edit
#itoctopus: Thanx for your reply!
This works for www.webwinkel.nl.
But not for the other domains on the same multistore.
For example I have www.webwinkel.nl, www.webwinkel2.nl and www.webwinkel3.nl.
With your code, they all will redirect to www.webwinkel.nl.
This is my whole htaccess now:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)webwinkel.nl [NC]
RewriteRule . - [E=MAGE_RUN_TYPE:website]
RewriteCond %{HTTP_HOST} ^(.*)webwinkel.nl [NC]
RewriteRule . - [E=MAGE_RUN_CODE:webwinkel]
RewriteCond %{HTTP_HOST} ^(.*)webwinkel2.nl [NC]
RewriteRule . - [E=MAGE_RUN_TYPE:website]
RewriteCond %{HTTP_HOST} ^(.*)webwinkel2.nl [NC]
RewriteRule . - [E=MAGE_RUN_CODE:webwinkel2]
RewriteCond %{HTTP_HOST} ^(.*)webwinkel3.nl [NC]
RewriteRule . - [E=MAGE_RUN_TYPE:website]
RewriteCond %{HTTP_HOST} ^(.*)webwinkel3.nl [NC]
RewriteRule . - [E=MAGE_RUN_CODE:webwinkel3]
# First condition - redirect non-www to www for all domains
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Second condition - redirect HTTP to HTTPS for a particular domain
RewriteCond %{HTTP_HOST} ^webwinkel\.nl$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.webwinkel.nl/$1 [R=301,L]
Add the following code to your .htaccess file to ensure that only a particular domain gets redirected to https://www. The first condition is to handle redirection from non-www to www for all other domains. The second condition is for redirecting your domain to https.
RewriteEngine On
# First condition - redirect non-www to www for all domains
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Second condition - redirect HTTP to HTTPS for a particular domain
RewriteCond %{HTTP_HOST} ^webwinkel\.nl$ [OR]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.webwinkel.nl/$1 [R=301,L]
Here is a link to an almost identical question htaccess for redirecting non-www to www while preserving http & https
How would this be written for the opposite - I want to redirect www to non-www while preserving http or https, whatever the link may be originally
You can have these 2 rules:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [L,R=301]
This was what worked, after some trial and error:
# Make all http use https and force non-www
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://mysite.ca%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
Sorry for not coming back to post this sooner, I'm learning...
Here is my current .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php
</IfModule>
I want to redirect all http requests to https, and all www requests to non-www, and all file requests to index.php
For example:
http://www.example.com to https://example.com
https://www.example.com to https://example.com
http://example.com/file.php to https://example.com/index.php
Everything seems to be working except the www part.. Any help please?
http://www.example.com to https://example.com
https://www.example.com to https://example.com
http://example.com/file.php to https://example.com/index.php
Maybe this will work:
RewriteEngine On
# Remove www from https requests.
# Next 3 lines must be placed in one .htaccess file at SSL root folder,
# if different from non-ssl.
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,L]
# Redirect all http to https
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (?:www\.)?(.+) [NC]
RewriteRule ^(.*) https://%1/$1 [R=301,L]
If it doesn't work, try replacing
RewriteCond %{HTTPS} off or on with
RewriteCond %{HTTP:X-Forwarded-SSL} off or on
You can add an additional rule dealing with the www part
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ https://%1%{REQUEST_URI} [L,R]
The RewriteCond captures everything after the www. and uses that in the RewriteRule as %1.
When everything works as you expect, you can change R to R=301.
Never test with 301 enabled, see this answer
Tips for debugging .htaccess rewrite rules
for details.
I have this site, example.com. What I want to do is force www on all pages, force https on one page, force http on all other pages.
I am using the following .htaccess code to redirect all http traffic to www:
#Redirect to www
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
and the following to set SSL on my "form" page:
#Force SSL on a specific directory
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteCond %{REQUEST_URI} form
RewriteRule ^(.*)$ https://www.example.com/form/$1 [R,L]
Problem is, when I hit https://example.com/, it does not redirect to www (https://www.example.com), and especially not http and www (http://www.example.com) like I want it to. I tried this:
#Redirect SSL to www
RewriteCond %{ENV:HTTPS} on [NC]
RewriteRule ^(.*)$ http://www.example.com$1 [R=permanent,L]
but that was a really dumb attempt and didn't work. How can I accomplish all three at once?
Try this:
# Handle nonSSL
RewriteCond %{HTTPS} on
RewriteRule !^/?form(/|$) http://www.ravicti.com%{REQUEST_URI} [L,R=301]
# Handle SSL
RewriteCond %{HTTPS} off
RewriteRule ^/?form(/|$) https://www.ravicti.com%{REQUEST_URI} [L,R=301]
# Add the missing www for both HTTP and HTTPS
RewriteCond %{HTTP_HOST} ^ravicti.com$ [NC]
RewriteCond %{HTTPS}:s (on:(s)|off:s)
RewriteRule (.*) http%2://www.ravicti.com%{REQUEST_URI} [L,R=301]