So far I have .htaccess file which is able to redirect correctly from (domain.com) to (https://www.domain.com) but not working if I go to www.domain.com and it must redirect (www.domain.com) to (https://www.domain.com)
I need (https://www) always before my site url
my .htaccess file
RewriteEngine On
RewriteCond !{HTTPS} off
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Replace your first 2 redirect rules with this rule:
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [L,R=301,NE]
Make sure to clear your browser cache before testing this.
Related
I would like to redirect https://www.example.com/page/jobseekers to https://www.example.com/jobseekers
I used
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Redirect /page/jobseekers /jobseekers
But its redirecting into https://www.example.com/jobseekers?page/jobseekers.
Place this rule just below RewriteEngine On line:
RewriteEngine On
RewriteRule ^page/(jobseekers)/?$ /$1? [L,NC,R=301]
# other rules go below
Make sure to test in a new browser or clear browser cachhe before testing.
hope some could help me.
I have a wordpress blog with 3 domains, .com, .es and .net. The .com is the target.
And i want to redirect from non-www to www as well.
The redirect from .es to .com works fine, and .net to .com too. But when i add the redirect from non-www to www is not working and the site doesnt load.
This is my .htaccess file...
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+$
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^myblog.com [NC]
RewriteRule ^(.*)$ http://www.myblog.com/$1 [L,R=301,NC]
#RewriteCond %{HTTP_HOST} ^myblog.es$ [OR]
#RewriteCond %{HTTP_HOST} ^www.myblog.es$
#RewriteRule ^(.*)$ "http\:\/\/www\.myblog\.com/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^myblog\.es$ [OR]
RewriteCond %{HTTP_HOST} ^www\.myblog\.es$
RewriteRule ^(.*)$ "http\:\/\/myblog\.com\/$1" [R=301,L]
RewriteCond %{HTTP_HOST} ^myblog.net [NC,OR]
RewriteCond %{HTTP_HOST} ^www.myblog.net [NC]
RewriteRule ^(.*)$ http://www.myblog.com/$1 [L,R=301,NC]
These rules should suffice for your needs:
RewriteEngine On
# redirect myblog.es and myblog.net (with or without www.) to www.myblog.com
RewriteCond %{HTTP_HOST} ^(www\.)?myblog\.(es|net)$
RewriteRule ^(.*)$ http://www.myblog.com/$1 [R=301,L]
# Force www on myblog.com
RewriteCond %{HTTP_HOST} ^myblog.com [NC]
RewriteRule ^(.*)$ http://www.myblog.com/$1 [L,R=301,NC]
I've tried several solutions posted here, none of them seem to work - I just get redirect errors.
What I am trying to do is redirect all traffic to https for:
http://domain.com
http://www.domain.com
https://domain.com
http://alias.com
http://www.alias.com
https://alias.com
should all go to: https: // www.domain.com
currently addresses starting like: http: // www won't redirect to https.
here is the htaccess file
RewriteEngine On
RewriteBase /
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
# Exclude /assets and /manager directories from rewrite rules
RewriteRule ^(manager|assets) - [L]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^myalias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myalias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^myotheralias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myotheralias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
You should get rid of the www redirects at the bottom:
RewriteCond %{HTTP_HOST} ^myalias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myalias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^myotheralias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myotheralias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
Don't need them, you just need a single redirect at the top, replace:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
with
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]
This should take care of all the redirects.
I've just added the following rule to force HTTPS on my payment page, simply because I'm not sure how to force HTTPS on just domain.com and not user1.domain.com - not quite sure how to do this or even if it's possible.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /join/payment
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
So I added that rule and it's working fine, however, is it possible to just force HTTPS on my full domain and not any of my sub-domains?
My full htaccess file
RewriteEngine on
RewriteCond $1 !^(index\.php|images|js|profile_pictures|fonts|stylesheets|robots\.txt)
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /join/payment
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{HTTP_HOST} !^((www\.)?)domain\.com [NC]
RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com
RewriteRule ^(.*)$ http://domain.com/site/%1$1 [L,NC,P]
RewriteCond %{HTTP_HOST} !^domain\.com$ [NC]
RewriteRule ^((?!site/).*)$ http://domain.com/site/$1?host=%{HTTP_HOST}&page=%{REQUEST_URI} [L,NC,P]
Questions
Is it possible to just force HTTPS on domain.com and not on subdomains? If it's possible to force HTTP instead of HTTPS on subdomains, I'd love to hear how to do that too.
I think that this should work:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /join/payment
RewriteCond %{HTTP_HOST} !^((www\.)?)domain\.com [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
That is, add a condition to check that the HTTP_HOST is www.domain.com or domain.com before adding https:// in front of it.
I setup .htaccess file for my domain and sub-domain. If I write manually https then both working fine but I want to force so that no one can open without https.
Also I want WWW with my main domain and Sub-domain without WWW. Below is my .htaccess code,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^app.domain.com$
RewriteCond %{REQUEST_URI} !^/app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/$1
RewriteCond %{HTTP_HOST} ^app.domain.com$
RewriteRule ^(/)?$ app/index.php [L]
And Is it possible to redirect user to sub-domain if they type www.domain.com/app/
You can insert these 2 rules:
RewriteEngine On
# force https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# force www for main site
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# remove www for app site
RewriteCond %{HTTP_HOST} ^www\.(app\.domain\.com)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} \s/+app[/\s] [NC]
RewriteRule ^ / [R=301,L]
RewriteCond %{HTTP_HOST} ^app.domain.com$
RewriteCond %{REQUEST_URI} !^/app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/$1
RewriteCond %{HTTP_HOST} ^app.domain.com$
RewriteRule ^(/)?$ app/index.php [L]