I'm trying to redirect:
http://www.example.com
https://www.example.com
http://example.com
.. to ..
https://example.com
I'm doing this because I have certs for https://example.com but not https://www.example.com
All works fine except the https://www.example.com which, in Safari, gives 'This connection is not private' error. In Chrome it's fine.
# BEGIN redirect www to non-www with SSL/HTTPS
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# END redirect
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
There are some Plesk settings which might effect this too (see image), but I have't got it to work.
Basically, Preferred domain: example.com and Permanent SEO-safe 301 redirect from HTTP to HTTPS will allow you to achieve the required results.
I would suggest removing the same redirects from .htaccess, since once it is defined in Apache configuration, duplicating rewrites may lead to conflicts resulting, for example, in Too many redirects errors.
If it still won't work in Safari, check Safari Develop menu for additional symptoms and google it or include it into the question.
Related
My situation is the following visiting my website...
Typing in browser http://example.com it redirects to http://www.example.com (with www. but insecure), and this is my problem.
Instead, if I type in the browser http://www.example.com it redirect correctly to https://www.example.com (secure connection).
I need to redirect both the URLs http://example.com and http://www.example.com always to https://www.example.com.
How to reach this result?
Thanks a lot for your help.
My .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$
RewriteRule ^(.*) https://www.example.com/$1 [R=301,L]
</IfModule>
Edit: the solution is to force https redirection:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule .* https://www.example.com%{REQUEST_URI} [L,R=301]
I have a SSL certificate for non www URL: https://example.com
I know there are many similar question, but none of them seems to solve my problem. Here is what I am trying to do:
Problem:
1) http://www.example.com -> https://example.com **www to non www DONE**
2) http://example.com -> https://example.com **http to https DONE**
So far, my .htaccess file looks like so:
# www to non www
# http to https
# SSL off
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^http\.(.*)$ [NC]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# https://www to https://
Does anyone know the solution? With the current solution, I only get the following error message from the browser:
Corrupted Content Error
The site at http://example.com/ has experienced a network protocol
violation that cannot be repaired.
The page you are trying to view cannot be shown because an error in
the data transmission was detected.
Please contact the website owners to inform them of this problem.
Here are the solutions that I already tried:
.htaccess redirect www to non-www with SSL/HTTPS
htaccess force https and redirect www to non-www, but no other subdomains
MANY MORE
Change your rules to this:
<IfModule mod_rewrite.c>
RewriteEngine on
# https://www and http://www to https://non-www
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule (.*) https://example.com/$1 [R=301,L]
# http://non-www to https://non-www
RewriteCond %{HTTPS} off
RewriteRule (.*) https://example.com/$1 [R=301,L]
</IfModule>
I am having problem with my opencart website while working with urls.
The problems are like -
1. When I use http://example.com : It works fine.
2. When I use https://example.com : It works fine with my non-www ssl certificate
3. When I use http://www.example.com : I lose my styles.
4. When I use https://www.example.com : I lose my styles and works as secured page
Now I want it in these ways :
1. When I use http://example.com : It should redirect to https://example.com
2. When I use http://www.example.com : It should redirect to http://example.com so that I can't lose styles.
3. When I use www.example.com : It should redirect to https://example.com
4. When I use only example.com : It should redirect to https://example.com
Here is my current .htaccess.txt
RewriteBase /
RewriteRule ^sitemap.xml$ index.php?route=extension/feed/google_sitemap [L]
RewriteRule ^googlebase.xml$ index.php?route=extension/feed/google_base [L]
RewriteRule ^system/download/(.*) index.php?route=error/not_found [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !.*\.(ico|gif|jpg|jpeg|png|js|css)
RewriteRule ^([^?]*) index.php?_route_=$1 [L,QSA]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
Please direct me how I can achieve what I want and how to fix styles problem.
Thanks in Advance !
Try this (replacing the last three lines of the .htaccess file):
RewriteCond %{HTTPS} on
RewriteCond %{HTTP:X-Forwarded-SSL} on
RewriteCond %{REQUEST_URI} !^/checkout/?.*$
RewriteRule ^(.*)$ http://url.com/$1 [R=301,L]
And make sure your opencart SSL settings are turned on with correct https:// URL in place.
And if the solution above does not work you can simply redirect all calls of www to non-www url where your website works perfectly with both SSL and styles.
You can try my solution. He works in 2020.
# Redirect to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.mystore\.com [NC]
RewriteRule (.*) http://mystore.com/$1 [R=301,L]
Browsed the whole site and can't really find a fix for my issue.
My whole site was https://, http://www.domain, http://domain would redirect to https://domain.com and then the whole site would run as https://smoothly.
I now need to make my homepage only, http:// because of a script I use that won't load on chrome because it's uses some http:// links, I cannot change the script so my only fix is to make my homepage http:// and then the rest, including all inner pages, automatically become https://
Here's what my htaccess looks like:
rewriteengine on
#rewritecond %{HTTP_HOST} ^www.domain.com$
#rewriterule ^$ "http\:\/\/domain\.com\/" [R=301,L] #528a28c9588af
RewriteCond %{HTTPS} on
RewriteRule (^$) http://%{SERVER_NAME}%{REQUEST_URI} [R=302,L]
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
#RewriteCond %{SERVER_PORT} 443
#RewriteRule ^(|/)$ http://%{SERVER_NAME}%{REQUEST_URI} [L,R=301]
rewritecond $0 !^(index\.php|front_assets|images|captcha|css|js|editor|assets|robots\.txt)
rewriterule ^.*$ index.php [L]
This is pretty bad but some of it works, it redirects the http://www homepage to http:// which is what i want, it also redirects https:// www. domain .com to http:// homepage which is what i want, but when i go to https:// domain .com it redirects to http:// homepage but gives a redirect loop version.
Basically what I want is to make http:// www . domain .com, https:// domain .com and https:// www . domain.com to redirect to http:// domain.com
and then once we're on http:// domain .com, if you click on anything or go to any inner pages I want it to show the https version, i just need the homepage to be http: //
Can anyone help, been trying to do this for days with no luck.
Thanks in advance
Try these rules:
RewriteCond %{HTTPS} on
RewriteRule ^$ http://%{HOST_NAME}/ [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^.+$ https://%{HOST_NAME}%{REQUEST_URI} [L,R=301,NE]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $0 !^(index\.php|front_assets|images|captcha|css|js|editor|assets|robots\.txt)
RewriteRule ^.*$ index.php [L]
I have my WordPress website in a subdirectory. I used the WordPress codex directions to set this up and all worked well until client asked me to add a 301 redirect to solve an issue with some links to an old domain on the Internet. The old domain name points to the new website but does not use a permanent 301 redirect. The current domain name is Encoreco.com.
The old domain points to the same place but it is not a 301 redirect (you can see that the URL does not change at the top and for some reason this means that my javascript slideshow doesn't work). Here is what happens: encoreconstructionco.com
When I add a 301 redirect to solve this problem, I get the infinite loop errors. Here is the line of code that attempts to solve the issue with the old domain but creates the infinite loop:
RewriteRule (.*) http://encoreco.com/$1 [R=301,L]
And here is my current .htaccess: Note - I tried taking the .html rewrite and the www rewrite out and that did not solve the problem.
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\.(.*)
RewriteRule (.*) http://%1/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteRule (.*) http://encoreco.com/$1 [R=301,L]
… will redirect everything, including correct requests, so you have to get an infinite redirect.
Restrict that rule to wrong host names only:
RewriteCond %{HTTP_HOST} !encoreco\.com
RewriteRule (.*) http://encoreco.com/$1 [R=301,L]