How to add www before subdomain in htaccess - .htaccess

So, we printed some cards but the card accidentally has www.sub.domain.com/example but when to try to go there it says the site cannot be reached but If we try to go to sub.domain.com/example it works.
The main website is made in WordPress but the landing pages (subdomains) are made using Unbounce can this be fixed using .htaccess? if so then which .htaccess file and how can we fix this.
Thank you

You need to redirect your www to non-www. That can be done by adding this to your .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.yourdomain.com [NC]
RewriteRule ^(.*)$ http://yourdomain.com/$1 [L,R=301]
Don't forget to change yourdomain with your domain.

Related

301 Direct to new Domain on https:// not https://www

I am looking to 301 an entire domain on https://www.olddomain.co.uk to a new domain on https://newdomain.com via .htaccess. Currently, the version I have will only work if you manually remove the www from the old link showing in Google SERP for the old domain listing - so it shows 'This site can’t be reached' when clicked. Removing the 'www' part of the URL and hitting return performs the redirect.
Current .htacess is:-
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ https://newdomain.com/$1 [R=301,L]
</IfModule>
And I've also tried:-
RewriteEngine on
RewriteCond %{HTTP_HOST} ^olddomain.co.uk [NC,OR]
RewriteCond %{HTTP_HOST} ^www.olddomain.co.uk [NC]
RewriteRule ^(.*)$ https://newdomain.com/$1 [L,R=301,NC]
Important to keep the SEO value form the old domain. Any assistance appreciated here.
Thanks in advance
Glennboy
Fixed in 2 parts:-
The DNS settings on the domain did not cover 'www' which was a simple error that would have stopped 'www' showing anyway.
Added a valid SSL Certificate to the old domain to ensure safe traversing of SSL - SSL
In short, the issue was not the .htaccess implementation which was perfectly valid and now working fine.

.htaccess redirect folder to subdomain

I've tried applying a few of the answers found on stackoverflow, but either I'm missing something or I'm plain dumb.
Basically I got a main domain name. This domain already has a non-www redirect. So http://domain.com becomes http://www.domain.com. This domain also has a mobile version found inside the the 'm' folder. So accessing the domain name like http://www.domain.com/m/ works and so does http://m.domain.com. What I'm trying to achieve is simple: anyone whom goes to the site via http://www.domain.com/m/, or http://www.domain.com/m/about should be redirected to the subdomain version so to http://m.domain.com or http://m.domain.com/about in the second case listed above.
Whatever I tried implementing ended up with errors, either I managed to disable direct access to m.domain.com, but it worked via domain.com/m/, or redirect loops.
Thanks!
You can use this code in your DOCUMENT_ROOT/.htaccess file of domain.com main .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?(domain\.com)$ [NC]
RewriteRule ^m/(.*)$ http://m.%1/$1 [L,NC,R=302]
# non-www to www
RewriteCond %{HTTP_HOST} !^(m|www)\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,NC,R=302]

.htaccess make subdomain the main domain without moving

I have my website in a subdomain:
subdomain.mydomain.co.uk
Now, I don't want to move subdomain.mydomain.co.uk but I want to use .htaccess to set it so that when someone types: mydomain.co.uk the url still remains mydomain.co.uk but acually shows subdomain.mydomain.co.uk
How can I do this?
Try putting this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^mydomain.co.uk [NC,OR]
RewriteRule ^(.*)$ http://subdomain.mydomain.co.uk/$1 [L,R=302,NC]
You could try doing an R=301, but beware of the dangers of using a 301 redirect. We had huge problems with our website at one point using 301 redirects as written about in this article: http://getluky.net/2010/12/14/301-redirects-cannot-be-undon/

Redirect www.example.com to example.com

I've a domain hosted on bluehost with iLister CMS installed in, the problem which I'm facing is http://www.advett.com/admin isn't responding because I registered advett.com/admin in the site_url field of iLister license.
How to redirect all the request for www.advett.com and www.advett.com/admin to advett.com and advett.com/admin respectively?
I know it can be done with .htaccess but I've not been able to find a solution till now.
Try putting this in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.advett\.com [NC]
RewriteRule ^(.*)$ http://advett.com/$1 [L,R=301]

htaccess command to prevent master site access via subdirectory?

I have hosting setup with a master domain (mapped to the web root) and then a number of addon domains (each with their own folder within the web root). At the moment you can visit www.masterdomain.com/addondomainsubdir and reach the same page as you would if you visited www.addondomain.com (which maps to /public_html/addondomainsubdir). I want to prevent this so if you visit www.masterdomain.com/addondomainsubdir then it will do a 301 redirect to www.addondomain.com. The new addondomain.com site is a single page site so it does not have to map any additional pages.
Adding rules to the htaccess file in the web root does notaffect anything as the subdir exists which is wierd as i thought the htaccess command should work even if there is a matching subdir (i've tried the following which works when there's no matching subdir):
RewriteRule ^addondomainsubdir?$ http://www.addondomain.com [NC,R=301,L]
Logically given it's reaching this directory I figure i need to add a command within the htaccess file in the addondomainsubdir directory however nothing appears to have any effect (i've got various other rules setup and they work fine).
I would be massively grateful if anyone explain the best way to rectify this?
Thanks so much for your help,
Dave
I know this is an old post, but it has never been successfully answered. So for all of you finding this via search, this should do what the OP is asking.
Add this line to your .htaccess file:
redirect permanent /addondomainsubdir/ http://www.addondomain.com
Try these rules in your .htaccess:
Options +FollowSymlinks -MultiViews
RewriteEngine on
# for http
RewriteCond %{HTTP_HOST} ^(www\.)?masterdomain\.com$ [NC]
RewriteCond %{SERVER_PORT} =80
RewriteRule ^([^/]+)/?$ http://www.$1.com/ [R=301,L]
# for https
RewriteCond %{HTTP_HOST} ^(www\.)?masterdomain\.com$ [NC]
RewriteCond %{SERVER_PORT} =443
RewriteRule ^([^/]+)/?$ https://www.$1.com/ [R=301,L]
Instead of putting a rule in your main .htaccess, I would make make a .htaccess for each add-on domain, putting each one in the respective subdirectory.
RewriteEngine on
RewriteCond %{HTTP_HOST} masterdomain\.com$ [NC]
RewriteRule ^addondomainsubdir(.*)$ http://www.addondomain.com/$1 [R=301,L]

Resources