I am running Magento site and in my .htaccess file I use this peace of code to redirect non www to www URL but it does nothing.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
My URL also contains HTTPS with it.
Try This....
<IfModule mod_rewrite.c>
RewriteEngine On
Rewritecond %{HTTP_HOST} !^www\.example\.com [NC]
Rewriterule (.*) http://www.example.com/$1 [R=301,,L]
</IfModule>
For dynamic domains:
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,QSA,NC,L]
Related
i just want to setting file .htaccess for redirect non www url to www. but the case is not common.
if the url like this https://<domain name>.com become https://www.<domain name>.com
i already set the code like this. but didn't work
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
</IfModule>
that code is working if we type just <domain name>.com in browser. but when someone type manualy on browser like this https://<domain name>.com i mean type manualy the https:// can it turn into https://www.<domain name>.com
so for this .htaccess i want to do result like this
if type
<domainName>.com it become https://www.<domainName>.com
www.<domainName>.com it become https://www.<domainName>.com
https://<domainName>.com it become https://www.<domainName>.com
http://<domainName>.com it become https://www.<domainName>.com
please help.
You may use this rule in site root .htaccess:
RewriteEngine On
# add www and turn on https in same rule
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
Try this:
# uniform host name
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^.*$ http://www.example.com$0 [R=301,L]
It includes a deep link forwarding.
You can try this
RewriteEngine On
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
I have the following domains:
example1.com
example2.com
example3.com
The domains point to /public_html/. There are three things I want to do in /public_html/.htaccess:
Redirect (with all parameters and paths) the domains example2.com and example3.com to the domain example1.com.
example1.com itself should get shown (if not, then redirect) always with https and www, means: https://www.example1.com
The custom root path for the domains is /public_html/. I want to change this to /public_html/example_path/.
I have the following in /public_html/.htaccess:
RewriteCond %{HTTP_HOST} ^example2.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example2.com [NC]
RewriteRule ^(.*)$ https://www.example1.com/$1 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^example3.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example3.com [NC]
RewriteRule ^(.*)$ https://www.example1.com/$1 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^example1.com [NC]
RewriteRule ^(.*)$ https://www.example1.com/$1 [L,R=301,NC]
RewriteCond %{HTTP_HOST} ^example1.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example1.com$
RewriteCond %{REQUEST_URI} !example_path/
RewriteRule (.*) /example_path/$1 [L]
This is nearly working as expected. But when opening http://www.example1.com there is no redirection to https://www.example1.com. This is only working when removing the last four code lines, that should change the root path.
For all other domains it's working.
Why isn't it woking for http://www.example1.com? And why is it only working when not changing the root path?
Add this rule to yours at the top of the .htaccess file
# http <> https
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example1.com/$1 [R=301,L]
Or check these rewrites instead of your rules:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.example1.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} !^www\.example1\.com [NC]
RewriteRule (.*) https://www.example1.com/$1 [R=301,L]
RewriteCond %{REQUEST_URI} !example_path/
RewriteRule (.*) /example_path/$1 [L]
</IfModule>
For specific domains (www/non-www example-other.co, www/non-www example3.com, www/non-www example2.com, example1.com)
<IfModule mod_rewrite.c>
RewriteEngine On
# http www/non-www example-other.com/any to https://www.example-other.com/any
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?example-other\.com [NC]
RewriteRule (.*) https://www.example-other.com/$1 [R=301,L]
# https non-www example-other.com/any to https://www.example-other.com/any
RewriteCond %{HTTP_HOST} ^example-other\.com [NC]
RewriteRule (.*) https://www.example-other.com/$1 [R=301,L]
# http www/non-www example1.com/any to https://www.example1.com/any
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(www\.)?example1\.com [NC]
RewriteRule (.*) https://www.example1.com/$1 [R=301,L]
# http/https www/non-www example2.com/any to https://www.example1.com/any
RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com [NC]
RewriteRule (.*) https://www.example1.com/$1 [R=301,L]
# http/https www/non-www example3.com/any to https://www.example1.com/any
RewriteCond %{HTTP_HOST} ^(www\.)?example3\.com [NC]
RewriteRule (.*) https://www.example1.com/$1 [R=301,L]
# https non-www example1.com/any to https://www.example1.com/any
RewriteCond %{HTTP_HOST} ^example1\.com [NC]
RewriteRule (.*) https://www.example1.com/$1 [R=301,L]
# Rewrite /any to /example_path/any
RewriteCond %{REQUEST_URI} !example_path/
RewriteRule (.*) /example_path/$1 [L]
</IfModule>
I am using bolt-cms with htaccess to redirect the root of the URL to the /public folder. Now I need to redirect http to https. How can I concatenate these two rules?
Here's my htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /public/([^\s?]*) [NC]
RewriteRule ^ %1 [L,NE,R=301]
RewriteRule ^((?!public/).*)$ public/$1 [L,NC,QSA]
RewriteCond %{HTTP:X-Forwarded-Proto} !https [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.mecanalisis.com.ar%{REQUEST_URI} [L,NE,R=301]
I have this script running on all my Laravel sites deployed on shared hosting to prepend www and to redirect all traffic to /public.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
What I'd like to do now is to tweak it so it redirects the traffic to /subfolder/public, but I'm having troubles making it work.
You can use:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
RewriteCond %{REQUEST_URI} !^/subfolder/public/ [NC]
RewriteRule ^(.*)$ subfolder/public/$1 [L]
</IfModule>
My server provides the default redirection from www.test.com to test.com
I want to remove the redirection for one specific file 'abc.php' there. How to go about it?
The default redirection provided in the .htaccess file is:
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>
Like this (for abc.php):
<IfModule mod_rewrite.c>
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{REQUEST_URI} !^(.*/)?abc\.php$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
</IfModule>