I want to remove www from URL but,
I am having an issue removing www from url with https (Apache Server).
I have added the following code in .htaccess file, it works, but when I go to http://www.zubizi.com it doesn't work, what I need to do for that????
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://zubizi.com/$1 [R=301,L]
Just make the following changes:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ https://zubizi.com/$1 [R=301,L]
RewriteEngine On
RewriteCond %{SERVER_PORT} !^443$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Related
I am deploying a Craft CMS site to a shared hosting account using Deployer.
The latest deployment is accessible from domain.com/current/public
My .htaccess file looks like the following, which strips current/public from the url and forces https:
RewriteEngine on
RewriteRule ^(.*)$ current/public/$1
RewriteCond %{HTTP:X-Forwarded-Proto} !=https
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
I now need to also redirect all urls to use www
How can I adjust my .htaccess to force www on all urls?
*** UPDATE ***
I have managed to solve the above with the following:
RewriteEngine on
RewriteRule ^(.*)$ current/public/$1
RewriteCond %{HTTP:X-Forwarded-Proto} !=https [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+) [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L]
When I go to example.com/admin it redirects to example.com/current/public/admin. How can I adjust my htaccess file to remove 'current/public' from admin urls?
Your http->https and www adding rule should be top most rule so that it works on original URI instead of a rewritten URI due to other rule.
RewriteEngine on
RewriteCond %{HTTP:X-Forwarded-Proto} !=https [OR]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+) [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(.*)$ current/public/$1 [L]
Make sure to clear browser cache before testing this rule.
Also add this redirect rule in /current/public/.htaccess:
RewriteCond %{THE_REQUEST} /current/public/(\S+) [NC]
RewriteRule ^ /%1 [R=301,L,NE]
I need to redirect all my users to another site keeping the current page structure in order to redirect them to the right page on the new domain.
My goal is redirect only the main domain, not the subdomain so I create this snippet but I'm not sure this is right:
RewriteCond %{HTTP_HOST} domain.com
RewriteRule /(.*) http://otherdomain.com [R=301,L]
I already have this in my htaccess that redirect users from www to non-www site:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
How can I make sure that if a user comes from www.domain.com he will be redirect to the new domain?
You can place new rule just below earlier rule like this:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule (.*) http://%1/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule (.*) http://otherdomain.com/$1 [R=301,L]
However if there is only one domain hosted then you can replace those 2 rules by this single rule:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule (.*) http://otherdomain.com/$1 [R=301,L]
I have a couple of sub-domains in addition to my main domain. Like so: domain.com, about.domain.com and new.domain.com.
All 3 have their own .htaccess file in their individual root folders.
I am trying to do 2 things:
all traffic gets routed to the same URL respectively.
the URL thankyou.php gets rewritten to /thank-you
Both of these work for the main domain, domain.com.
But they do not work for the sub-domains.
Here is what works for domain.com:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index.php$ http://www.domain.com [R=301,L]
RewriteRule ^thank-you/?$ thankyou.php [NC,L]
Appreciate any help with this.
Use this .htaccess for your sub domain:
Options +FollowSymLinks
RewriteEngine on
#RewriteCond %{HTTP_HOST} !^www.
#RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [R=301,L,NE]
RewriteCond %{THE_REQUEST} \s/+index\.php\s
RewriteRule ^index.php$ / [R=301,L]
RewriteRule ^thank-you/?$ /thankyou.php [NC,L]
Did you try this yet?
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule (about)(/.*|$) $1.domain.com/$2 [R=301,L]
I have an .htaccess file for some domains sitting on same folder but leads to different content that is determined by php according to the domain name.
I want only one of them to redirect all requests to ssl domain.
How that's can be done?
When I use redirect rules it transfer all domains:
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%mydomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%mydomain.com%{REQUEST_URI} [L,R=301]
If you want to skip mydomain.com from this http->https redirection:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?mydomain\.com$
RewriteCond %{HTTPS} off
RewriteRule ^ https://%mydomain.com%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%mydomain.com%{REQUEST_URI} [L,R=301]
I want to redirect all non-www to www - if the request is through http it should redirect to http://www.domain.com, if the request is through https then direct to https://www.domain.com
I have tried the following in my .htaccess, but it redirects everything to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301
I have used this code and it's resolving perfectly. Please check whether it's correct or not.
RewriteEngine On
RewriteBase /
#Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
# Redirect to HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://www.pnrstatusbuzz.in/%{REQUEST_URI}
You can use this rule as your first rule:
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]