I have the following code to force WWW in url
rewriteCond %{HTTP_HOST} !^www.example.com [NC]
rewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
I want to add a subdomain max.example and refer to www.example.com/update/max directory
If I do not add any rule, max.example.com will redirect to www.example.com/update/max . If I remove force WWW in url it works. But I still need force WWW in url. How to write the rule?
Thanks!
Change your rule to this:
RewriteCond %{HTTP_HOST} !^(www|max)\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]
Related
I need to make a request to https://subdomain.www.domain.com rewrite the URL to https://subdomain.domain.com
Which part of the below rewrite do I change to achieve this? I'm guessing I have to put the subdomain in front of the www, but what do I put there, also how do I capture all subdomains - what's the general rule for all subdomains?
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
You may use this rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.www\.(domain\.com)$ [NC]
RewriteRule ^ https://%1.%2%{REQUEST_URI} [R=301,L,NE]
I want that a url of the form
http://www.example.com
redirects to
example.com
How can I achive this? I found that .htaccess Remove WWW from URL + Directories comes pretty close to my question, but I do not know how to change it appropriately.
To remove www ,you can use :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$
RewriteRule ^ http://%1%{REQUEST_URI} [NE,L,R]
or
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.example\.com$
RewriteRule ^(.*)$ http://example.com/$1 [NE,L,R]
I have been able to find solutions to each of these redirects separately but I can't find something that does both correctly.
I need the website to redirect from:
http://somesite.com.au to https://somesite.com.au
http://www.somesite.com.au to https://somesite.com.au
https://www.somesite.com.au to https://somesite.com.au
The main combination that I'm having trouble with is:
https://www.somesite.com.au to https://somesite.com.au
Currently I am using the following in my htaccess file:
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Ensure we are using HTTPS version of the site.
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# Redirect www to non-ww
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
What should I be using in my htaccess to make this work?
You're causing a loop because your www rule redirects to http://. Just change it to redirect to https:// instead:
# Redirect www to non-ww
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
I am trying to redirect all visitors from non-www to www, which is currently done via
RewriteEngine On
RewriteCond %{http_host} ^mysite.com
RewriteRule ^(.*) http://www.mysite.com/$1 [R=301,L]
but a would like a forced exception for a specific page to redirect from www to non-www...
is RewriteRule ^/?$ exception.html [L] the only solution?
Well if you want to prevent a page from non-www to redirect, you have to set the rewrite rule before the one that redirect.
The option [L] will prevent next rules to be checked.
RewriteEngine On
RewriteCond %{http_host} ^mysite.com
RewriteRule ^exception\.html$ exception.html [L]
RewriteCond %{http_host} ^mysite.com
RewriteRule ^(.*) http://www.mysite.com/$1 [R=301,L]
I hope this help you
Try this:
Redirect www.mysite.com/exception.html -> mysite.com/exception.html (OPTIONAL)
Only add this RewriteRule if you also want to redirect www.mysite.com/exception.html to mysite.com/exception.html.
If you simply only want exception.html to be an exception from redirecting mysite.com to www.mysite.com then you don't need this rule.
# Redirects www.mysite.com/exception.html to mysite.com/exception.html
RewriteCond %{HTTP_HOST} ^www\.(.+)
RewriteRule ^exception.html$ http://%1/exception.html [R]
Redirect mysite.com -> www.mysite.com
# Redirects mysite.com to www.mysite.com. We must add a condition to avoid an infinite redirect loop with exception.html
RewriteCond %{HTTP_HOST} ^(mysite\.com)
RewriteCond %{REQUEST_URI} !^exception.html$
RewriteRule (.*) http://www.%1/$1 [R=301,L]
Using these directives, I can redirect any non-www subdomain to the www subdomain:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.|$) [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
What I need to achieve is to redirect the www subdomain only.
For example I want to redirect only blog.myname.com to www.blog.myname.com. The rule in the config above will redirect blog.myname.com to www but it also redirect myname.com to www.myname.com, which is not what I am looking for. I also need to redirect all queried subdomain not just blog.myname.com
How can I do this?
You can use this code to achieve that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^((?!www)[^\.]*)\.myname\.com$ [NC]
RewriteRule ^ http://www.%1.myname.com%{REQUEST_URI} [L,R=301]
Above code withh redirect all subdomains but will not effect myname.com or www.myname.com.
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog\.myname\.com$ [NC]
RewriteRule ^ http://www.blog.myname.com{REQUEST_URI} [L,R=301]