I am trying to redirect visits to https://www.domain.co.uk to http://www.domain.co.uk. I have researched this, but have come to a dead end.
Many people including people here, on SO suggest to use:
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This is my entire .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have tried putting the https rewrite code above, below and within the <IfModule mod_rewrite.c>. But had no luck.
I know the .htaccess is being read, as I can make it return a 500 internal server error when using random letters.
Thanks for your help.
EDIT
Anubhava found out my server isn't listening for port 443 as my VirtualHost has no entry for it.
Here's that section of my httpd.conf
If it is WP then in your permalink settings change your site's URL to http://domain.com which seems to be https://domain.com at present. WP forces that URL if you're using a different one.
Your full .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} on
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Related
I have a domain with a working htaccess file, which redirects all http traffic to https. This is/was working all fine.
Here is that .htaccess file:
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.well-known/acme-challenge
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
Just now, I have installed wordpress in a sub-folder called "blogg" like this:
www.example.com/blogg/
I noticed right away that the blog was not https. So I went to wordpress admin and changed the URL in general settings from "http" to "https". This seems to have made all links in wordpress, as well as the admin page, use https.
Unfortunately it didnt help when going to the blogg in the web browser, it is still http, although https works if I enter it manually in the browser.
Here is the htaccess file in the wordpress directory (example.com/blogg/.htaccess):
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blogg/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blogg/index.php [L]
</IfModule>
# END WordPress
I am new to .htaccess, and would like some help in finding the right code for all my domain to be https, including the blog. Help is appreciated.
To be clear, I want all http requests to automatically go to https instead.
I have tried adding this line in the second .htaccess file: (no luck though).
RewriteCond %{HTTPS} off RewriteRule ^(.*)$
https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
BR
You can try something like this:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blogg/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blogg/index.php [L]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*) https://%{SERVER_NAME}/$1 [R,L] //SERVER_NAME = your actual domain name for WP
</IfModule>
# END WordPress
You can also look into this code since its an easier version. It will give you idea about WP htaccess if in root folder as well. :)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L,NE]
# 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
I'm needing to rewrite urls to be "pretty" instead of queries: they need to be /kw/blah instead of kw.php?kw=blah. I've tested the code several times with online checkers, and they say it works/is syntactically correct.
The two sites I used to check are: https://htaccess.madewithlove.be (url testing was with /kw/melbourne-web-design and http://www.htaccesscheck.com
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} blueshiftwebservices\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://blueshiftwebservices.com/$1 [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^kw/([^/]*)$ landing.php?kw=$1 [L]
</IfModule>
# END WordPress
I'm getting an error of 404 Page not found only with the pretty url, not the url that contains the query.
The live site definitely refers to the .htaccess file, so I'm lost at what to do?
The rule RewriteRule . /index.php [L] matches all URLs. So you must insert the rule RewriteRule ^kw/([^/]*)$ landing.php?kw=$1 [L] before it.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# redirect to https
RewriteCond %{HTTP_HOST} blueshiftwebservices\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://blueshiftwebservices.com/$1 [R,L]
# are you sure you need it?
RewriteRule ^index\.php$ - [L]
# make it "pretty"
RewriteRule ^kw/([^/]*)$ landing.php?kw=$1 [L]
# process the rest
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I have added my website to Cloudflare for use of flexible SSL. Everything on static content is ok. For example, I can access my files directly with https (Ex: https://www.samanik.com/logo.png).
but I can't access the WordPress site. I have changed both the site_url and home_url in the db. I have added codes to .htaccess, but when I type my website without https it redirects to https (as I want). But, nothing is shown there. I get an error called ERR_TOO_MANY_REDIRECTS I don't know how to fix this problem.
Here is my .htaccess content.
# 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
<IfModule mod_rewrite.c>
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]
</IfModule>
Can anyone help me?
You can redirect to HTTPS using action hook as well.
Add the below code in your **functions.php**:
function redirectToHTTPS(){
if($_SERVER['HTTPS']!="on"){
$redirect= "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];
header("Location:$redirect");
}}
add_action('init','redirectToHTTPS' );
For detailed guide, check here.
in General Settings set your WordPress Address (URL) Site Address (URL) to https://...
update:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I am hoping that you can help me with the htaccess rewrite rule below.
# BEGIN WordPress
# WPhtc: Begin Custom htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have recently changed my wordpress site from http to https... The problem is that old url's redirect to the domain name instead of the https version of that page
eg
if I access the following page https://domain.com/test/testing/ it works 100%, now if I change the https part to http then the page redirects to https://domain.com instead of to https://domain.com/test/testing/ how do I fix it so that if you go to the old version page http://domain.com/test/testing/ (the not https version) that it redirects to https://domain.com/test/testing/ instead of just the domain name https://domain.com
You have to find a workaround for %{REQUEST_FILENAME} since this only represents the file that is accessed. But you obviously want to access the SSL vHost.
So you might hardcode the https into your .htaccess.
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
This might help you alot. (found the code above there)
I've been struggling also with this issue and finally I found a solution for the home redirection and the wordpress in the same htaccess file, and finally it also works for old http links, redirecting to https:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$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
I tried your solution. It worked well, but if you do that you'll need to manually change all your internal links.
This works better ;)
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
I use this .htaccess for wordpress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
# BEGIN WordPress
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I need to redirect all "http" requests to "https". I did something like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://example.com.br/site/$1 [R=301,L]
</IfModule>
It seems work appropriately, but this is not loading files. Files should be opened using the url:
https://example.com.br/site/wp-content/themes/briefing/css/style.css
but instead, the page try to load:
https://example.com.br/site/css/style.css
"https://" does not appear in Browser. I am using Wordpress, the site is inside a "site" folder. My big problem is because I have a ajax request and had the following error:
XMLHttpRequest cannot load https://exemple.com.br/site/wp-content/themes/briefing/includes/loopHandler.php?numPosts=3&pageNumber=1. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://example.com.br' is therefore not allowed access.
My htacess file begins with:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
What should I do?
You need to replace your RewriteCond:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
by the following:
RewriteCond %{HTTPS} !on
The HTTP:X-Forwarded-Proto you currently using only checks if a proxy forwarded non https traffic. This is not really related to your problem. You need a general check if incoming requests are not https requests: %{HTTPS} !on.
You may can try that:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.mysite.com/my-sub-domain/$1 [R,L]
</IfModule>
# END WordPress
Keep your rules like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://example.com.br%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
Then do make sure your home and site URLs in WP's permalink settings also has https:// URLs.