I have a website which uses an SSL cert on production. At the same time, a staging version (staging.domain.com) should only resolve to http.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.in$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I know it can be done using htaccess, but I simply cannot get it to work.
www.domain.com / domain.com should redirect to https
staging.domain.com should redirect to http
Related
I have this htaccess:
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteCond %{HTTP_HOST} ^(.*)\.example\.com
RewriteCond %{REQUEST_URI} !^/([a-zA-Z0-9-z\-]+)
RewriteRule ^(.*)$ https://example.com/subfolder/%1 [L]
It is redirecting to https and also .example.com to example.com/subfolder/ ,
but when I open some subdomain, it gives me a certificate error.
Can I prevent this somehow?
main domain should redirect to https
all subdomains should redirect without ssl to the https://example.com...
thank you
Yesterday I Installed SSL on the server. Since than I can't reach some pages.
www.example.com/amsterdam/shoes
example.com/amsterdam/
^ both do not redirect to https://, not even http://
www.example.com/amsterdam
^ does redirect to https://
How do I redirect all pages to HTTPS with www via .htaccess?
RewriteEngine on
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NC,L,R=301,NE]
This will redirect both http or non-www to https://www
Use:
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
OR you can try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
I’m looking to do this:
Force the https for my main domain.
http to https://www.
http://www to https://www.
But not for subdomains
http://subdomain.domain.com to https://subdomain.domain.com
Can some one help me i can't find this
You can use that in your root .htaccess:
RewriteEngine on
# redirect to https www
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)(domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
# redirect to http subdomain
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^((?!www).+\.domain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
[EDIT]
RewriteEngine on
# redirect no-www to www only main domain, not with subdomain
RewriteCond %{HTTP_HOST} ^(domain\.com)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
# redirect http to https all domain
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Currently, I have following redirection setup in htaccess to redirect www and non-www URL to HTTPS with www.
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I have now created a subdomain dev.example.com. But when I run it, site redirects to HTTPS with www. How can I stop it, and load dev without any redirection?
Add another condition to the HTTPS rule:
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule ^(.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !dev\.example\.com$ [NC]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I have a website with SSL. The redirect from http to https seems to work fine. my problem is how should I redirect the https://example.com to https://www.example.com.
I have tries this but it's not working.
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} (.*)
RewriteRule .? https://%1%2 [R=301,L,U,NE]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]