I have .htaccess in the root directory of web which should redirect all requests to https. Here is the code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^web\.php5\.sk$
RewriteRule ^$ www/ [L]
RewriteCond %{HTTP_HOST} ^web\.php5\.sk$
RewriteRule (.*) www/$1 [L]
But it creates an endless loop which redirects from http to https and vice versa. Where could be the problem? First two lines comes from server administrator as response to my request for https. They handles lot of http requests from devices which are not able to make https request... Thanks.
Hi friend What about this code
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
#replace this yourdomain.com into your domain name
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
This is a simple, clean and tested code to redirect all traffic from http to https with www (you can also remove www from your URL anytime, just remove www from url something like this https://yourdomain.com/$1).
Related
Hi after 1 week of research i'm still stuck with my domain redirections
I want my http://domain.fr pointing to https://www.domain.fr
I'm trying with htaccess file with no success...
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.*
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
When i'm testing my redirections it seems https://www.domain.fr is redirecting itself without understading why...
have you guys any idea ?
The problem is in your 2nd RewriteRule
RewriteCond %{HTTP_HOST} ^www\.*
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]
You rule does a permanent redirection of www domain to the same location ie : ( www.e ample.com => www.example.com ) that is why you got the redirect loop error.
To redirect http urls to https ,first of all you need to check if the request scheme is http. You can use RewriteCond %{HTTPS} off to check the non - secure http connection and then use RewriteRule to redirect the request to https .
Use the following simple Rule to redirect http to https :
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]
Make sure to clear your browser cache before testing this.
I am trying to add redirect rules using .htaccess for such goals:
Redirect all http pages to https.
Redirect all www http and https pages to non www https.
My .htaccess code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
Everything is working good except one:
http redirects to https (all pages)
https www redirects to https non www (main page and subfolders)
But https://www.example.com/1/page.html does not redirect to https://example.com/1/page.html (both pages open)
What is the problem? How to write an .htaccess rule to redirect all the pages to https non www?
You can use this to remove www and force https:
RewriteEngine on
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://example.com%{REQUEST_URI} [R=301,L,NE]
Make sure you clear your cache before testing this. Combing the two rules will help to speed up your website too, instead of having to run two seperate rules.
we have many domain on our server but we want to redirect some domain http to https permanently .
like our domain
http://example.com/ //main public folder
http://example.com/member //member folder
http://example.com/online //online folder folder
please tell me what specific rules for these domain only
Use this in your .htaccess:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
That will force https on everything. If you want to do it for specific folders, use this:
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} folder
RewriteRule ^(.*)$ https://www.example.com/folder/$1 [R,L]
I need a script to .htaccess to 301 redirect http to https, but a page needs to be accessed by HTTP. Example:
example.com/* redirects to https://example.com/*
example.com/page1 not redirect to https://example.com/page1
Just use this:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
So it will just set your SSL to https for all pages, even if someone access it via http.
Use this if you want to force https for all except the directory /page1
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !page1 [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
How can I rewrite all traffic using "https" and "www" to "https" without the "www". I do not want any rewrites done on non-ssl traffic (besides the existing code below). I also already have a rewrite for clean urls going on at the same time. The SSL cert is purchased on the non-www URL which is why I am asking how to do this.
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
Thanks for your time.
[EDIT]
Ended up getting this to work:
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www.mysite.com$ [NC]
RewriteRule ^(.*)$ https://mysite.com/$1 [L,R=301]