I searched stackoverflow but my htaccess file is a little different than what I saw. Here's what I currently have:
Options -Indexes
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
I've seen a couple of different methods for forcing HTTPS in an htaccess file, and both worked for me on their own, but getting both www + https no matter WHAT someone types into their browser is what I'm after.
I think this what you're after.
Options -Indexes
RewriteEngine On
RewriteCond %{HTTPS} !^on [OR]
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
Let me know how it works out for you.
This should work:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Related
What I want to achieve should be quite simple:
Redirect all traffic to HTTPS and the www. subdomain. And to achieve this I used the following rule:
# Canonical https/www
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ([^.]+)\.domain.com [NC]
#RewriteCond %{HTTP_HOST} !^www\. [NC]
#RewriteCond %{HTTP_HOST} ^(.*)$ [NC]
RewriteRule ^(.*) https://www.%1/$1 [R=301,L]
</IfModule>
However, if I follow a link like this:
http://www.example.com
I end up here:
https://www.www.example.com
So then I found this question: .htaccess: http://www redirects to www.www
And I completely replaced the rule I used above with the rule suggested in the accepted answer:
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^(.*)$ https://www.%1%{REQUEST_URI} [R=301,L]
However now I get the ERR_TOO_MANY_REDIRECTS error, and the site completely refuses to load.
Can someone help me out here?
Check this rewrite in your .htaccess file, maybe it help
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
I have to redirect my domain from http to https. In my htaccess I have already.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
This snippet redirect everything without "www" to "www".
When I change this to
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
The result is:
http://www.example.com/folder/page.php
becomes
Location => https://www.example.com/folder/page.php
Fine!
https://example.com/folder/page.php
becomes
https://www.example.com/folder/page.php
Fine!
but:
http://example.com/folder/page.php
becomes
Location => https://example.com/folder/page.php
but it has to be
Location => https://www.example.com/folder/page.php
How is it possible to fix this?
I know all of this redirects:
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
but I need only one redirection instead of two 301.
You can use the following rule
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www [OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$
RewriteRule ^ https://www.%1%{RERUEST_URI} [NE,L,R=301]
Clear your browser cache before testing this.
I have found a solution here:
https://webmasters.stackexchange.com/questions/84757/htaccess-redirect-non-www-to-www-with-ssl-https
The second answer by #w3dk is working.
RewriteEngine On
RewriteCond %{SERVER_PORT} !=443 [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
Your site needs to be accessible by both www and non-www over SSL for the .htaccess redirect to trigger.
With letsencrypt its no problem to have this 2 certs.
I have this .htaccess file
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
I want to modify .htaccess, that site always show https in url. I tried
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
this don't work. I tried also
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
but in this case I got This webpage has a redirect loop error..
Help me to configure that please.
The only reason why this code not working
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
this is what the certificate give you cloudflare or something other similar service, when you hasn't direct control to your ssl certificate.
I had such problem with ssl from cloudflare, and I solve that with
RewriteCond %{HTTP:CF-Visitor} '"scheme":"http"'
RewriteRule ^(.*)$ https://domain.com/$1 [L]
I don't know why this is happening, but when I visit my site from any other browser other than safari, it redirects me to the https version. However, if I visit the same site using safari (on iPhone, mac, or iPad), it says there is a redirect loop.
My htaccess code:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
Options -Indexes
</IfModule>
I don't know why this is happening. Any help is highly appreciated. Thanks!
I fixed it by using this instead.
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Try :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_URI} !^/public
RewriteRule ^(.*)$ public/$1 [L]
Options -Indexes
</IfModule>
Replace example.com with your domain name in HTTP_HOST string pattern.
I have found a thousand other topics asking for help with this, but none of their solutions seem to work for some reason.
I just purchased SSL for my domain a couple of days ago because I am accepting credit/check cards on my site and I want my customers to feel and be secure.
Anyways, this is what my .htaccess file looks like at the moment:
php_flag display_startup_errors off
php_flag display_errors off
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^buy-wow-accounts index.php [NC]
RewriteRule ^sell-wow-accounts sell.php [NC]
RewriteRule ^about-khaccounts about.php [NC]
RewriteRule ^buy-sell-wow-accounts-faq faq.php [NC]
RewriteRule ^khaccounts-feedback feedback.php [NC]
RewriteRule ^payment-plan payment-plan.php [NC]
RewriteRule ^customer-login customer-login.php [NC]
RewriteRule ^customer-center customer-center.php [NC]
RewriteRule ^privacy-policy privacy.php [NC]
RewriteRule ^buy-world-of-warcraft-wow-accounts/page-([0-9]+) listing.php?pageid=$1 [L,NC]
RewriteRule ^buy-world-of-warcraft-wow-accounts listing.php [L,NC]
RewriteRule ^world-of-warcraft-wow-acc/([^/]*)\.html$ account.php?acc=$1 [NC]
What I want to do is force WWW if it is not already in the URL and ensure that HTTPS (SSL) is forced as well. I have a ton of links out there to my site and most of them are just links like 'www.khaccounts.net', 'http://khaccounts.net', and 'khaccounts.net'.
I want to ensure that each of these different old links will be forced into having WWW and HTTPS. In order words, I want people to have the URL - 'https://www.khaccounts.net' no matter what URL they took to get to my site.
Thanks!
Right after your www rules add:
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Also, change your www rule to https:// so that there aren't 2 redirects.
Looks like you're rewriting all of your urls to the root. Why don't you try:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
This works in showing the proper URL when khaccounts.net is hit, but still throws a redirect loop.
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://www.khaccounts.net/$1 [R=301,L,QSA]
Try replacing these lines :
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
With this :
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.khaccounts\.net$ [NC]
RewriteRule ^(.*)$ https://www.khaccounts.net/$1 [R=301,L,QSA]