my htaccess rewrite code for redirect
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI}
i am getting this on my pingdoom test:
Remove the following redirect chain if possible:
http://panjabi.club/
https://panjabi.club/
how can i remove this.
my WordPress is installed over https, I intend to use only that. this was not before, plus I am using CloudFlare
Related
I'm having trouble getting these redirects to work under all conditions. I'm hoping I can fix it with .htaccess but there may be something mucked up with the way I'd previously tried to force redirects through my host's control panel.
Anyway, olddomain.com/whatever, with http:// or https:// and with or without www should permanently redirect to https://www.newdomain.com/whatever.
At one point I had everything except https://olddomain.com redirecting properly. Now I've broken it and I'm just getting the too many redirects error.
I believe both domains have a Let's Encrypt certificate attached to them. The old domain doesn't need to be secured if that makes a difference.
According to https://serverfault.com/a/728957, you can use this snippet to help redirect users to a https://www of the site.
RewriteEngine On
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Hope that helps!
I've recently tried to force HTTPS on my website by using various directives contained in mod_rewrite. However it didn't workout very well and now it's recommented to use the Redirect directive from mod_alias. I've got everything in a subfolder and I wrote:
Redirect "/folder/" "https://mywebsite.org/folder/"
in my .htaccess file, but it keeps giving me the ERR_TOO_MANY_REDIRECTS error.
This code in .htaccess will redirect http://example.com to https://example.com
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I'm using the following code to redirect all requests to one domain to another single page (without stuff after the /)
RewriteEngine on
RewriteRule ^(.*)$ http://example.com [L,R=301]
The above works if I go to olddomain.com or olddomain.com/something, but doesn't work when going to olddomain.com/something/somethingelse
How can I get the rewrite rule to work for all directory depths?
Should have worked, You can try this code also:
RewriteRule ^ http://example.com%{REQUEST_URI} [L,R=301]
What is the proper .htacess rule to redirect every request by a user to any page on my server to https://that page
For example, mydomain.com or http://mydomain.com would go to https://mydomain.com
Also, mydomain.com/projects/1.html would go to https://my domain.com/projects/1.html
No matter how deep the requests go, all requests from the browser go to be https://that location.
How would I do this?
RewriteEngine on
RewriteRule (.*) https://mydomain.tld$1
Ensure the vhosts are in different folders so it doesn't go recursive obviously.
If you are using Apache, you need to use mod_ssl by using the SSLRequireSSL Directive.
then you need to use mod_rewrite for a redirection.
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I am currently using this .htaccess to redirect all the requests for pages with a directory to my index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|cas)
RewriteRule ^(.*)$ /seattle/index.php/$1 [L]
And this works just fine and produces urls that hide the index.php, and I have code in index.php that makes urls clean looking.
But now I need to force pages to connect via ssl, so I tried
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteCond $1 !^(index\.php|cas)
RewriteRule ^(.*)$ https://example.com/seattle/index.php/$1 [L]
and it works to force ssl, but now it also forces the url to include the index.php:
https://example.com/seattle/index.php/pagename
instead of what I want
https://example.com/seattle/pagename
What am I missing?
To change protocol (HTTP -> HTTPS) and/or domain name (www.example.com -> example.com) the proper redirect ("301 Permanent Redirect" or "302 Found/Temp Redirect") is required.
Therefore you cannot combine rewrite and redirect and still showing original URL. It has to be 2 different rules and the one for changing protocol/domain should be listed first. For example:
RewriteEngine on
# force HTTPS for all URLs
RewriteCond %{HTTPS} =off
RewriteRule . https://example.com%{REQUEST_URI} [R=301,L]
# other rewrite rules
RewriteCond $1 !^(index\.php|cas)
RewriteRule ^(.*)$ /seattle/index.php/$1 [L]
The rule I have added will redirect ALL HTTP URLs to HTTPS. If you need only some of them to be redirected -- add appropriate conditions via additional RewriteCond line(s).
The %{HTTPS} is the most common and kind of "proper" way of checking if SSL is ON or OFF (but it is all depending on your specific circumstances and server config). When checking against %{HTTPS} you are safe against situation when your site is running on non-standard port (other than 80). You can use %{SERVER_PORT} =80 instead (will work for majority of cases).
With the above rules the rewrite for http://example.com/seattle/pagename will occur in 2 steps:
301 Redirect to https://example.com/seattle/pagename
Rewrite (internal redirect) to /seattle/index.php/pagename