Another developer wrote these rules rules:
[ISAPI_Rewrite]
RewriteCond Host: (?:.+\.)?mydomain\.com
RewriteCond URL ^/mydomain.com/(.*)
RewriteCond METHOD GET
RewriteRule ^/mydomain.com/(.*) /$1 [I,R]
RewriteCond Host: (?:.+\.)?mydomain\.com
RewriteCond METHOD POST
RewriteRule ^/mydomain.com/(.*) /$1 [I]
RewriteCond Host: (?:.+\.)?mydomain\.com
RewriteRule (.*) /mydomain.com/$1 [I,L]
The problem is I'm not sure if those lines are the ones causing the site to redirect to the http://www.mydomain.com whenever we try accessing http://www.mydomain.com/shop. I am also concerned if those lines have an impact on SEO. BTW, the site is running on IIS and not Apache.
Any help would be very much appreciated. Thanks.
Related
I'm trying to write a rule that means if anyone goes to any address across the whole domain, it will replace http: with https:
My current rule is;
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://mydomain.co.uk/members$1 [R,L]
This works for my main domain but I have different subdomains which I need to write to work in the same way. I'd ideally not like to write a rule for each of the subdomains.
If I go to https://example.mydomain.co.uk/members it shows the correct content but if I got http://example.mydomain.co.uk/members it redirects to https://mydomain.co.uk
Thanks in advance for your help!
EDIT: I forgot to mention, this rule is in my /members directory not root.
You could do this:
ServerAlias *.mydomain.com
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(.+)\.mydomain\.com$
RewriteRule ^(.*)$ https://%1.mydomain.com/$1 [R=302,L]
try this:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
I have a problem with my .htaccess and https redirection.
First of all, I have consulted these links to find a solution but none could help me.
List of links :
.htaccess redirect http to https
ModRewrite with HTTPS
https://www.ndchost.com/wiki/apache/redirect-http-to-https
htaccess redirect to https://www
https://serverfault.com/questions/116206/how-do-i-use-htaccess-to-always-redirect-from-http-to-https
When I load the page with http, the .htaccess redirect me to https but when I load the page with https, I have an infinite loop.
Here is my .htaccess code :
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteCond %{HTTP_HOST} ^(api|www|dev|stefano|sav)\.
RewriteCond %{REQUEST_URI} !^/(api|www|dev|stefano|sav)/
RewriteCond %{DOCUMENT_ROOT}/%1 -d
RewriteRule ^(.*)$ %1/$1 [L]
Is anybody can help me create a redirect condition (http to https) ?
You are leaving off the Rewrite Flags You need to tell it force the redirection with R flag and optional provide status code which is recommended 301, 302 etc.
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
By the way, every example you linked to shows the answer using the R flag, not sure why you didn't use exact examples :)
Solution if behind devices like load balancer.
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I have been fighting with this same problem for hours. It seems that I needed the solution for systems behind a load balancer. Perhaps this is because I am using Cloudflare with my site.
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
After adding the above lines to my .htaccess file, I deleted the cache on Cloudflare and the site loads as it should.
I was trying to get an entire directory/section of my website to automatically re-direct to https (secure) using the .htaccess file, so I found a solution on here. It turns out it re-directs my ENTIRE site to HTTPS except for the homepage. I'd like it to only re-direct the /php/ folder and anything inside it.
Thanks in advance for any help!
Here is my code in .htaccess:
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} php
RewriteRule ^(.*)$ https://beanstalkwebsolutions.com/$1 [R,L]
You can use this rule as your very first rule:
RewriteCond %{HTTPS} off
RewriteRule ^php(/|$) https://beanstalkwebsolutions.com%{REQUEST_URI} [NC,R,L]
I have a pretty basic CodeIgniter setup for a site that now needs to be run entirely on SSL. So, I figured I need to force https by some .htaccess rules as that seems to be the most intuitive and straight forward approach. This is what I do:
config:
$config['base_url'] = 'https://cooldomain.com';
$config['index_page'] = '';
.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
#remove ugly index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
The result is that I get lots of identical GET requests in my FireBug resulting in a "blank" error screen.
Doesn't CI URI patterns like .htaccess redirects? Surely this must work?
Shouldn't
RewriteCond %{S} off
actually be
RewriteCond %{HTTPS} off
?
Because this answer came up quite high on my google search I'll answer this one.
Reading from the comments there seems to be a loadbalancer infront of the webserver. When this happens you can check the following as well to see if there's a https connection:
RewriteCond %{HTTP:X-Forwarded-Proto} =http
I want to :
- switch from http to https if http is used
- redirect the subdomain to index?o=subdomain except www
- redirection the subdirectory to index?u=user
Example :
http://www.mydomain.com will be redirected to https://www.mydomain.com
http://subdomain.mydomain.com will be redirected to https://www.mydomain.com/index?o=subdomain
https://subdomain.mydomain.com will be redirected to https://www.mydomain.com/index?o=subdomain
http://subdomain.mydomain.com/user will be redirected to https://www.mydomain.com/index?o=subdomain&u=user
https://subdomain.mydomain.com/user will be redirected to https://www.mydomain.com/index?o=subdomain&u=user
Is mod_Rewrite the best to do that ? Any idea ?
Thanks in advance
I don't have time to test it right now, but you can try this and see if it works. There may be some potential for some things to go wrong, so if you have trouble with it I'd be happy to work out any kinks later. Also, I think that I covered everything you wanted to do, but let me know if I left something out.
RewriteEngine On
# Force redirect to HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}/$0 [R=301,L]
Edit: I've updated the ruleset below. I thought about your question though, and aren't you going to have issues attempting to serve up your subdomains over TLS/SSL? That aside, one of the following should do what you want (without errors this time, I hope):
If you wanted internal redirection:
RewriteCond %{HTTP_HOST} !=mydomain.com
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{REQUEST_URI} !^/index
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^\.]+)[^/]*/([^/]+)?
RewriteCond %1&u=%2 ^([^&]+)(&u=.+)?
RewriteRule ^.*$ /index?o=%1%2
If you wanted external redirection:
RewriteCond %{HTTP_HOST} !=mydomain.com
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{REQUEST_URI} !^/index
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^\.]+)[^/]*/([^/]+)?
RewriteCond %1&u=%2 ^([^&]+)(&u=.+)?
RewriteRule ^.*$ https://www.mydomain.com/index?o=%1%2 [R=301,L]