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]
Related
I'm trying to accomplish the following:
non-http force to https - works
www force to non-www - works
website loaded from subfolder (/web) - works
test.example.com load different subfolder (/test) - does not work
4, Does not work, the condition is met to go to /web. Can't understand how to change this into /test
the .htaccess code I use:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^test.example.com$
RewriteRule ^(.*)$ /test/$1 [L,NC,QSA]
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^example.com$ [NC,OR]
RewriteRule ^(.*)$ /example/web/$1 [L,NC,QSA]
With your shown samples please try following htaccess rules file here. Please make sure to clear your browser cache before testing your URLs. In case you have further more rules(apart from shown ones) then make sure these Rules are before those rules.
RewriteEngine On
##Apply https to uris here..
RewriteCond %{HTTPS} !on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
##Apply non-www to uris here..
RewriteCond %{HTTP_HOST} ^(?:www\.)(example\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,L,R=301]
##Apply test to all uris here..
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test [NC]
RewriteRule ^(.*)/?$ example/web/$1 [L,NC,QSA]
##Apply test to all uris here..
RewriteCond %{HTTP_HOST} ^test\.example\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/test [NC]
RewriteRule ^(.*)/?$ www.example.com/test/$1 [L,NC,QSA]
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]
We are busy with a name change for our webshop and i am working on our HTACCESS to redirect 1700 links. from those 1700 links there are 177 links that are changing in our new webshop. So they have to be in the HTACCESS. The other links keep the same and i redirect them now with a general rewriterule.
The only problem now is that he does not look well what the exact link is. For example see below my HTACCESS.
RewriteEngine on
# Redirect to domain with www.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Same for HTTPS:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/(.*)$ https://www.new.nl/vloerkleden/ [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/vintage-vloerkleed/(.*)$ https://www.new.nl/vloerkleden/vintage-vloerkleed/ [R=301,L]
RewriteCond %{HTTP_HOST} ^old.nl [NC,OR]
RewriteCond %{HTTP_HOST} ^www.old.nl [NC]
RewriteRule ^(.*)$ https://www.new.nl/$1 [L,R=301,NC]
When i type now the following url in the browser www.old.nl/vloerkleden/catagorie/vintage-vloerkleed/ he links me to www.new.nl/vloerkleden in stead of www.new.nl/vloerkleden/vintage-vloerkleed.
Your problem in this line :
RewriteRule ^vloerkleden/categorie/(.*)$ https://www.new.nl/vloerkleden/ [R=301,L]
Nothig to present (.*)$ in substitution https://www.new.nl/vloerkleden/ so , it should look like this https://www.new.nl/vloerkleden/$1 because $1 will represent (.*) in pattern.
Also , you could do this with another rules and you could also sumerize your rules like this :
RewriteEngine on
# the folwoing rules will force every request for both old & new into https://wwww:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^(?!.*www\.)(.*)$
RewriteRule .* https://www.%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/(.*)$ https://www.new.nl/vloerkleden/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?old\.nl$ [NC]
RewriteRule ^vloerkleden/categorie/vintage-vloerkleed/(.*)$ https://www.new.nl/vloerkleden/vintage-vloerkleed/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?old.nl [NC]
RewriteRule ^(.*)$ https://www.new.nl/$1 [L,R=301,NC]
Note: clear browser cache then test.
My domain www.abc.com is now redirecting to https://www.abc.co.uk
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
These code works exactly what I want. After that I created a subdomain. www.x.abc.co.uk
Now I want to redirect that to http://x.abc.co.uk (without https)
I used this
RewriteCond %{HTTP_HOST} ^x\.abc\.co\.uk [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But browser says it has redirect loop.
How can do that?
If these are two different htaccess files then give this a try.
RewriteEngine On
#redirect www.x.abc.co.uk without www to http
RewriteCond %{HTTP_HOST} ^www\.x\.abc\.co\.uk [NC]
RewriteRule ^(.*)$ http://x.abc.co.uk%{REQUEST_URI} [L,R=301]
I modified your original rule so you don't have two rewrite rules and still direct to www.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTPS} !^on$
RewriteRule ^(.*)$ https://www.abc.co.uk%{REQUEST_URI} [L,R=301]
I've got this code in .htaccess now:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} (.+)$
RewriteRule ^(.*) http://www.%1/$1 [L,R=301]
Now I need my cgi script cgi-bin/test.cgi redirected to https://www.example.com/cgi-bin/test.cgi
I've already tried
RewriteRule ^cgi-bin/test.cgi$ https://www.example.com/cgi-bin/test.cgi [L]
and some more other variation but it doesn't work
Please help!
Try:
RewriteCond %{HTTPS} off
RewriteRule ^cgi-bin/test.cgi$ https://www.example.com/cgi-bin/test.cgi [L,R]