I have a windows server online and some pages load in http I would like to force them to https how could I do that ?
I have no idea where to start
You will need to change the code to the following in the .htaccess file.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
You can reffer the following blog for reference if this doesn't work.
https://www.catalyst2.com/knowledgebase/server-management/how-to-force-https-on-linux-and-windows-servers/
Related
Pulling my hair out. I need to force to HTTPS and getting too many redirects with the below in .htaccess file. Based on my research on Stack, this should work. Cleared cache, cookies, all that.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Ok, figured it out. Because I'm behind a load balancer, I had to replace:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
WITH:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]
More info on why you need that header here: Load Balancers and HTTPS
I had a similar problem (with Codeigniter and using AWS Classic ELB) but the above solution did not work for me. I had to apply the rewrite conditions and rules in the https.conf file and then restart the apache server. See here for how to do it. Also worth noting that AWS don't recommend the .htaccess approach (not sure why):
https://aws.amazon.com/premiumsupport/knowledge-center/redirect-http-https-elb/
https://www.youtube.com/watch?v=hvqZV_50GlQ
I had a similiar problem with Laravel 6 on a shared hosting. When I configured CPanel to redirect my app to a secure https url, it kept redirecting infinitely.
I had this in my .htaccess
RewriteCond %{HTTP_HOST} ^biblioteca\.vallenateca\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.biblioteca\.vallenateca\.com$
RewriteRule ^/?$ "https\:\/\/biblioteca\.vallenateca\.com" [R=301,L]
I added this two lines.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-SSL} !on
RewriteCond %{HTTP_HOST} ^biblioteca\.vallenateca\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.biblioteca\.vallenateca\.com$
RewriteRule ^/?$ "https\:\/\/biblioteca\.vallenateca\.com" [R=301,L]
And it solved it.
In laravel 8, the default on the .htaccess file is:
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
This worked for me and I'm using Inmotion hosting:
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,QSA]
I want to change my domain name http://flexy.tk to https://flexy.tk and I don't know what to edit in this .htaccess file I am new so plz help in detail and I don't want to get any risk but I try I changed the last line from http to https but I don't know is it working or not so thanks in advance
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.flexy\.tk$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteRule ^/?$ "http\:\/\/flexy\.tk\/" [R=301,L]
before giving downgrade try to help first friend
Just do it like this:
RewriteEngine on
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
I try to make a redirect from a special folder to a special host.
When somebody enter http://mydomain.com/administrator he should be redirected to https://a-otherdomain.com/mydomain.com/administrator
What I have is this in a .htaccess file in DOCUMENT_ROOT .. but it want work :(
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (^|\.)mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/administrator(/*) [NC]
RewriteRule ^/administrator/(.*)$ https://a-otherdomain.com/mydomain.com/administrator/$1 [QSA,R=301,L]
Any Ideas?
Update:
now I use this, which works in apache configuration files for the vhost:
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (^|\.)mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} ^/administrator/ [NC]
RewriteRule ^/(.*)$ https://a-otherdomain.com/mydomain.com/$1 [R=301,L]
Thanks,
Thomas
RewriteRule doesn't match leading slash in a URI.
Try this code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} (^|\.)mydomain\.com$ [NC]
RewriteRule ^administrator(/.*|)$ https://a-otherdomain.com/mydomain.com/$0 [R=302,L,NC]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
I'm building a preprod environment where the client and developpers will be able to check that everything is working fine for their website they are about to put up but i must disable all HTTPS redirection because at this point it would fall in the PROD site wathever the HOSTNAME is sent in the request.
This is one of the examples i'm using:
RewriteCond %{HTTP_HOST} (www\.)?domain\.com
RewriteCond %{HTTP_HOST} ^s\.domain\.com
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/?basket/$
RewriteCond %{REQUEST_URI} !^/?basket/add/
RewriteCond %{REQUEST_URI} !^/?basket/delete/
RewriteCond %{REQUEST_URI} !^/?basket/modify/
RewriteCond %{REQUEST_URI} !^/?basket//add/
RewriteCond %{REQUEST_URI} !^/?basket//delete/
RewriteCond %{REQUEST_URI} !^/?basket//modify/
RewriteCond %{REQUEST_URI} !^/?basket/info_panier.js
RewriteRule ^/?basket/.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
Problem is, even if i visit:
http://s.domain.com/basket//coordonnees/login/
It still redirects me to the HTTPS version, but i have a rewrite condition on the s.domain.com saying to skip this rule... What am i doing wrong?
CrazyCoder
Never mind i found it two seconds later, but this might help other people:
The condition:
RewriteCond %{HTTP_HOST} (www\.)?domain\.com
Came clashing on the condition:
RewriteCond %{HTTP_HOST} ^s\.domain\.com
Because i didn't put a ! off the start. If i put ! before the (www.)?domain.com it will not match s.domain.com and thus work fine...
I am having a problem setting up my Zend framework project.
I have xampp/htdocs/quickstart
my server name is mydomain.com. I want to access my project at https://mydomain.com/quickstart(note that i am using https, dont think if this could be a problem)
i used the following .htaccess
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{SERVER_NAME}/$1 [R,L]
RewriteRule ^\.htaccess$ - [F]
RewriteCond %{REQUEST_URI} =""
RewriteRule ^.*$ /public/index.php [NC,L]
RewriteCond %{REQUEST_URI} !^/public/.*$
RewriteRule ^(.*)$ /public/$1
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^.*$ - [NC,L]
RewriteRule ^public/.*$ /public/index.php [NC,L]
And i am getting a 404 error , why does this happen?
I am sorry, i am no expert in configuring .htaccess. All i want to do is route all the requests in quickstart to quickstart/public. and to access my zend project at https://mydomain.com/quickstart/
i am getting a 404 error with above .htaccess(found on Internet)
My problem is is i already ahve other apps running on the server and i want to build a project on /quickstart. i also cannot create a subdomain. Can you please help me with proper .htaccess config.
Try with this,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]