.htaccess http to https not working - html

despite searching for previous answers, I couldn't see one which addresses my issue, so hope someone can help?
I recently redirected an old html company site to a new wordpress site with .htaccess rules (obvs different domain)
however, shortly afterwards I updated the new domain with an ssl cert. The old site was just a regular http:
I changed the .htaccess rules for the https: but obvs I have done it incorrectly as the redirect does not work.
this is what I am using.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old-domain.co.uk$ [OR]
RewriteCond %{HTTP_HOST} =www.old-domain.co.uk
RewriteRule (.*) https://newdomain.com$1 [R=302,L]
</IfModule>
what do I need to change to have it redirect correctly?
thanks for your assistance.

I prefer this variant for redirecting from http to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Also there are a lot of plugins for wordpress that help with that. They also help with redirecting all request to resources (images etc) to https

It works for me.
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301]

Related

Stop subdomain redirecting to main domain

When I search for the subdomain.domain.es I'm redirected to domain.es.
Code in htaccess file:
RewriteEngine On
RewriteBase / RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://dominio.es/$1 [R=301,L]
My hosting company gave me the htaccess so my web was redirected from http to https but I have no clue of what any of this code means.
I'm new to web programming so I hope you can help.
Thanks so much!
This answer worked for me. I hope this can help someone else!
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

htaccess why is site redirecting to //

In my htaccess I am redirecting all non https to https.
It works, but its also adding in an extra '/', so the url is
'https: //www.[MY SITE URL].co.uk//'
Why is this? To be honest, I don't really know what all this in my htaccess is doing, its copied from googling answers to 'redirect all requests to https'
My htaccess:
Options -MultiViews
RewriteEngine On # Turn on the rewriting engine
RewriteBase /
#RewriteCond %{HTTP_HOST} ^(www\.)?jobooz\.com [NC]
#RewriteRule ^(.*)$ https://www.jobooz.co.uk/$1 [R=301,L,NC]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}/$1
RewriteRule ^/?$ /php/index.php [NC,L] # Home page
I've also noticed any deeper urls like '/search-jobs/jobs-near-me' that I add to the url then get duplicated too, to '/search-jobs/jobs-near-me/search-jobs/jobs-near-me' when redirected to https.
All urls work fine if I go directly to the https version.
Any help appreciated, thanks.
The following rewrite rule has a problem:
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI}/$1 [R=301,L]
The gist of why you are seeing repeated fragments in the rewritten URL is that (.*) matches everything, and that already includes the host and URI. Instead, you can try redirecting any incoming request on port 80 to HTTPS.
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]

Need Help in my website IP Canonicalization .htaccess

i have searched the whole internet to find solution my website is www.hrxlevels.tk and ip address associated with website is this 31.170.163.33 and want the .htaccess for ip to redirect to domain
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteEngine On
RewriteCond %{HTTP_HOST} ^hrxlevels.tk [NC]
RewriteRule ^(.*)$ http://www.hrxlevels.tk/$1 [L,R=301]
RewriteEngine On
RewriteCond %{HTTP_HOST} ^31\.170\.163\.33
RewriteRule ^(.*)$ http://www.hrxlevels.tk/$1 [L,R=301
RewriteBase /
and this code is not working for ip canonicalization but works great for url cononicalization please help please!
please use this detail and please write the .htaccess file for my website.
My webhost is 000webhost.com

difference between www.xyz.com and xyz.com and how to redirect .htaccess

I have a site and am using Google Webmaster tool. I created the setting within the tool for the site twice: once as www.xyz.com and once as xyz.com. The statistics from both are different once I drill down into details.
I want to stick with www.xyz.com. How can I make everyone go to xyz.com be redirected to www.xyz.com? and will this harm my ranking or indexing in google?
regards,
sorry if the question is simple :)
with htaccess, i use the following for forced www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]
although you might be best doing the following if if it is for SEO purposes
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.htm
RewriteRule ^(.*)index.htm$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/index.html
RewriteRule ^(.*)index.html$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/home.htm
RewriteRule ^(.*)home.htm$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^.*/home.html
RewriteRule ^(.*)home.html$ http://%{HTTP_HOST}/$1 [R=301,L]
as this also removes any index or home page part of the url.
in webmaster tools in settings, you can also select always use www, which will merge the data for both domains under a single www domain (although you will be able to see both www and non-www listed in GWMT)
Use preffered domain, more instructions here:
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=44231
Specify a preferred domain:
On the Webmaster Tools Home page, click the site you want.
Under Site configuration, click Settings.
In the Preferred domain section, select the option you want.
You could also use 301 redirect:
http://support.google.com/webmasters/bin/answer.py?hl=en&answer=93633

How to force http- NOT https using htaccess

I have ONE directory for my entire domain that I want to force https, which is "/docs". In the /docs folder, I have the following htaccess file:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
This is forcing https to everything in the /docs directory, which is what I want it to do. The problem I am having is trying to force REMOVE https back to http for all other areas of my site. In the root folder of the site (which is running wordpress), I have the following htaccess file:
# 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
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/docs/?.*$
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
Unfortunately, this is not working. I can still access other areas of my site over https.
What do I need to change to get this to work correctly?
Since the accepted answer doesn't actually answer the question, I figured I'd post my solution to this. Add this to your .htaccess file to force HTTP instead of HTTPS:
# BEGIN Force HTTP
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ http://yourdomain.com/$1 [R=301,L]
# END Force HTTP
Try the Force non-SSL plugin for wordpress.
The "WordPress Force HTTP" plugin was the only thing that worked for me. It changes https to http for not just the front page like most of the answers out there, but also changes https to http for all sub-directories in your website.
https://en-au.wordpress.org/plugins/wp-force-http/
Why do you need to revert back to http? If you have the proper SSL certificates you might as well keep your access secure. Unless you are concerned about the load on your system.
I know this is not answering the question, but I want to emphasize that the question is asking on how to do a bad practice, which shouldn't be done in the first place.