Currently I have the following in my .htaccess file for a forum site.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule ^/?$ http://example.com/forums/ [L,R=301]
It works perfect for redirecting everything like (http)://example.com, www.example.com, (http)://www.example.com etc. to example.com/forums which is what I wanted.
I now want to have everything redirect to (https)://example.com/forums but am running into problems with existing links such as example.com/forums/stuff.
I can only get example.com to redirect to https://example.com/forums, any direct links such as example.com/forums/stuff etc. will not redirect to the https version, any ideas?
You need 2 redirect rules. One rule to redirect landing page to forums page and another rule to redirect http -> https:
RewriteEngine On
# redirect landing page to /forums/
RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com [NC]
RewriteRule ^/?$ https://%{HTTP_HOST}/forums/ [L,R=301]
# redirect http -> https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
Related
I have a functional URL shortening site. Recently I added SSL to the website and configured the .htaccess for proper redirecting. The issue is that all of the http:// requests, redirect back to the homepage https://websi.te
Currently, I've tried setting up redirecting as follows:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
An example of what's going wrong:
User types http://websi.te/keyword or websi.te/keyword and they are redirected to https://websi.te instead of https://websi.te/keyword
Change your rewrite to this:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
$1 is first group match ^(.*)$, it's your request.
I just purchase my site SSL license, I googled and try a few different codes to be added to htaccess.
1st set of code I used
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
2nd set of code I used
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
ref:https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
However, the site keep redirects all inner pages without https to https homepage.
Eg. http://example.com/tag1/tag2 to https://example.com
But I need it to redirect from http://example.com/tag1/tag2 to https://example.com/tag1/tag2
Is there something wrong with my code? or it server configuration related?
I have Drupal 7 site with default .htaccess file. I need redirect all site possibilities to one https site. What I need is:
http://example.com -> https://example.com
http://www.example.com -> https://example.com
https://www.example.com -> https://example.com
I have tried many options but I still get error: "This Webpage has a redirect loop."
Default .htaccess looks like:
.htaccess
[Edited] I found solution:
for remove www and retirect to https: RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]<br>
RewriteRule ^ https%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
for redirect non www to https:
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,L]
You can also try setting the base_url setting in settings.php. By default it's commented out, but you can uncomment it and set it with the desired protocol:
$base_url = 'https://'.$_SERVER['SERVER_NAME']; // NO trailing slash!
This has saved me on multiple occasions, in particular when trying to force HTTPS from behind a proxy server, and using the Domain Access module in Drupal 7. I found the solution here.
Maybe someone is interested in these redirections (to https AND to www.*):
http://example.com to https://www.example.com
and
http://www.example.com to https://www.example.com
.htaccess:
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I was trying to redirect my webpage to normal http but one specific url should be redirect to https.
I tried this:
RewriteCond %{HTTPS} off
RewriteRule ^site-name\.html$ https://domain.com/site-name.html [L,R=301]
But this way, the normal website is reachable through http and https.
Maybe you guys can help me with that.
You can have another to redirect https->http for all other pages:
RewriteCond %{HTTPS} on
RewriteRule !^site-name\.html$ http://domain.com%{REQUEST_URI} [NE,L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^site-name\.html$ https://domain.com%{REQUEST_URI} [NE,L,R=301]
I would like to redirect all none-https requests to https excepts requests to sub-domains. For example
http://example.com/ => https://example.com/
http://example.com/page => https://example.com/page
But
http://m.example.com/ REMAINS http://m.example.com/
This is what I have in my .htaccess, which redirects all requests (including sub-domians):
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I know that I have to add a condition before the RewriteRule but I am quite not sure about the syntax.
Add another RewriteCond before your RewriteRule:
RewriteCond %{HTTP_HOST} !=m.example.com
To Exclude any Subdomain from https rewrite add
RewriteCond %{HTTP_HOST} !=/(.*?)/.example.com