htaccess to rewrite all HTTPS requests to HTTP version - .htaccess

I'm trying to disable HTTPS on domain names that do not have SSL certificates, I am using this code but it doesn't seem to be doing anything. My website is running Wordpress and the wordpress htaccess is working fine, but the HTTPS bit seems to be nothing. This is the code I am using with wordpress' htaccess:
I'm now using the code from the 'possible duplicate' above and it's not working for me:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
# BEGIN WordPress
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress
</IfModule>
Any help would be greatly appreciated!

You're using capture group # 1 i.e. $1 without using capturing a group using square brackets.
Change your code to this:
RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]

There was a misconfiguration on the server that was preventing the rewrite rules from functioning. I contacted Host Gator and they confirmed they had installed an SSL certificate improperly which was causing the problems.
Thank you all for your help; I greatly appreciate it.
Below is the email from HostGator for archival purposes of this question.
Hello,
Thank you for contacting Host Gator, I will be more than happy to
assist you with this.
We apologize for any inconvenience this has caused.
It appears your SSL was installed incorrectly, we have updated your IP
for the SSL and you should have no other issue with it.
If you have any other questions please let us know.
Regards,
Elizabeth R.
HostGator.com LLC

**Always use https for secure connections
Replace 'www.example.com' with your domain name
(as it appears on your SSL certificate**)
Put this code inside .htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]
Reference

Related

WAMP server redirect old domain names to new domain name?

I have WAMP server where there are 5 projects hosted 192.168.0.10 as
192.168.0.10:80
192.168.0.10:81
192.168.0.10:82
192.168.0.10:83
192.168.0.10:84
now I have changed and moved all these projects to new server 192.168.0.11 as
192.168.0.11:80
192.168.0.11:81
192.168.0.11:82
192.168.0.11:83
192.168.0.11:84
I want if someone still access
192.168.0.10:80/* it should be redirected to 192.168.0.11:80/*
what will be best solution?
for time being I can keep old server and place there some file e.g. .htaccess for redirection
I tried below in .htaccess file at old server but still it is not redirecting
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
#code below is for redirtect
RewriteEngine On
RewriteCond %{HTTP_HOST} ^192.168.0.10$
RewriteRule ^(.*)$ http://192.168.0.11$1 [R=301,L]
</IfModule>
With your shown samples, could you please try following. Please make sure to place these rules always at top of your htaccess file. Values and etc are totally based on shown samples by original poster here.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^192\.168\.0\.10:81$
RewriteRule ^ http://192.168.0.11:%{SERVER_PORT}%{REQUEST_URI} [NE,R=301,L]
NOTE: As per OP's suggestion, edited line with port 81 here in condition line.

Redirect & SEO (SSL Redirect)

So I bought an SSL for my website, and to redirect the HTTP to HTTPS, I use the following
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=301,L,NE]
It works great. No problem. But the issue is when I do some basic Speed Tests & SEO test, theres always an error saying things similar to "disable redirect for better speed, seo".
But If i delete .htaccess redirect, there would be issues with HTTP/HTTPS
How can i solve this problem? Is there any other way to make the SSL work without redirecting?
Just In Case Information; I use Godaddy Linux Server.
Thanks in advance.
use this code in your .htaccess file to solve SSL problem
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
if RewriteEngine already "On" then no need to "On" again. I hope this will work perfectly.

Magento non www to www

I am pulling my hair out here.
I have created a landing page which is http://www.pps-supplements.com/samples
it works and you can access it fine - no problems.
If you type in the address bar:
pps-supplements.com/samples
it takes you to the home page which is not good and causing me to have a headache.
My website is working well for non www to www on home page and categories but not on cms pages.
I have read a few posts on here and tried their solutions which is to edit the htaccess file but it hasn't fixed it.
Does anyone have any ideas how I can resolve this issue??
Pretty please!
You could try this in your .htaccess file....
Be sure to add it above any other rewrite rules or conditions you may already have in your htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
Rewritecond %{HTTP_HOST} !^www\.pps-supplements\.com [NC]
Rewriterule (.*) http://www.pps-supplements.com/$1 [R=301]
</IfModule>
This will redirect any domain that is not www.pps-supplements.com to the version with www's
Also very handy for using when pointing multiple domains at a site.
Also, be sure that the webserver is set-up to receive the non www version, as in that it is listening for that version, as well as for the version with www's.
For anyone else looking at the accepted answer and running into issues with it not working you may have other Rewrites in place that need to be stopped from executing.
You can stop further execution by including the "L" param.
Example:
Rewritecond %{HTTP_HOST} !^www\.domain\.com [NC]
Rewriterule (.*) http://www.domain.com/$1 [R=301,L]
I wanted to redirect from example.com/category/ to www.example.com/category/
and I found solutions:
turn off Auto-redirect to Base URL in backend
and use this code in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
</IfModule>
For Magento Multistore-Setups:
Rewritecond %{HTTP_HOST} ^example\.com [NC]
Rewriterule (.*) http://www.example.com/$1 [R=301,L]

.htaccess - redirecting www and non-www subfolder to same location

I'm trying to forward all the content in subfolders to a respective root.com/folder on my root server.
I've successfully used the code below to forward country.root.com to the root.com/folder, however when I type is www.country.root.com into the web browser - it does not redirect (I've tried making it work but nothing happens - this is the code I'm back to).
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^uk\.domain\.com
RewriteRule ^(.*)$ http://www.domain.com/uk$1 [R=permanent,L]
Have been messing around with this for a while. Could anyone help me?
Thanks
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(.*)uk.domain.com
RewriteRule ^(.*)$ http://www.domain.com/uk$1 [R=permanent,L]
This should help you, works for me.

htaccess SSL directory redirect and reverse

I have found similar questions, however no-matter what I try I am unable to get htaccess to do what I need it to. What I'd like is to direct visitors to an SSL connection when visiting one (or more) virtual subdirectories and then reverse this when they leave these selected subdirectories.
My rules look like this:
Options +FollowSymlinks
RewriteEngine on
#switch on SSL in /directory/ only
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/directory/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
#switch off SSL in other folders
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/directory/
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteRule ^([^/\.]+)/?$ /index.php?var1=$1 [NC,L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+).html /index.php?var1=$1&var2=$2 [NC,L,QSA]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?var1=$1&var2=$2 [NC,L,QSA]
It seems that switching on SSL and switching off SSL conflict and when I try to access any page via https://www.domain.com/foo/ I am correctly redirected to http://www.domain.com/foo/.
However, when trying to access http://www.domain.com/directory/ (which should be SSL) I am redirected to http://www.domain.com/index.php?var1=directory and not https://www.domain.com/directory/.
I would really really appreciate a bit of guidance over where I'm going wrong. I've trawled through stackoverflow and the web for hours and hours looking for an answer but I'm just going round in circles and can't see the wood from the trees.
Thank you for any guidance/help you can offer.

Resources