Redirect www.example.com to example.com - .htaccess

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]

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.

How to add www before subdomain in 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.

htaccess file: Prevent redirecting addon domain pages

I have a main ssl domain https://www.a.com and a normal addon domain http://www.b.com on the same server. I use this .htaccess rule for a.com to redirect an old page in that website to a new one:
Redirect permanent /my_page.php /my_page
It works just fine. When i access a.com/my_page.php it redirects to a.com/my_page. The problem is that the addon domain b.com has the same page name inside its folder, so when i access b.com/my_page.php it also redirects to b.com/my_page. I need to prevent this redirection for the addon domain.
Note: I have tried to use this redirection rule instead but it didn't work at all:
RewriteRule https://www.a.com/my_page.php https://www.a.com/my_page
And this one too didn't work:
RedirectMatch 301 ^a.com/my_page.php$ https://www.a.com/my_page
After some reading and studying i was able to fix this using the RewriteRule instead. Here's the new code:
RewriteCond %{HTTP_HOST} ^.*a.com$ [NC]
RewriteCond %{REQUEST_URI} ^/my_page\.php$ [NC]
RewriteRule ^(.*)$ https://www.a.com/my_page [L,R=301]

.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]

Redirect URLs of Domain that is already 301 Redirected

I don't even know how to ask this question correctly, because I have never seen it done before. I am pretty competent with editing name servers, creating a records, and cnames etc, but I have no idea if this is even possible.
I have a client that owns a several domains that all point at the same site. So say the main domain is www.client-site.com. So then www.other-domain-1.com and www.other-domain-2.com are simply set as 301 redirects to point at www.client-site.com.
So all is good until now he is requesting that www.other-domain-1.com/facebook and www.other-domain-1.com/linkedin point to his facebook page or linkedin profiles instead of redirecting to the main domain.
The 301 redirect is happening at the registrar, and I don't believe there is a way to do what he wants from there. But I am thinking I could instead point it at the web host nameservers and include it as a addon domain, and then use the .htaccess file to do the 301 redirect of only the hostname, and then redirect as desired the hostname/paths.
So what is the proper way to do this? Something like...
Redirect 301 http://other-domain-1.com/facebook http://facebook.com/account
Redirect 301 http://other-domain-1.com/linkedin http://linkedin.com/profile
Redirect 301 http://other-domain-1.com http://client-site.com
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# facebook redirect
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^facebook/?$ http://facebook.com/account [L,NC,R=302]
# linked-in redirect
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^linkedin/?$ http://linkedin.com/profile [L,NC,R=302]
# rest of the redirects
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^ http://client-site.com%{REQUEST_URI} [L,NE,R=302]
So the Solution that worked on my server based on anubhava answer above was
facebook redirect
RewriteCond %{HTTP_HOST} ^(www\.)?other-domain-1\.com$ [NC]
RewriteRule ^facebook/?$ http://facebook.com/account [L,NC,R=302]
Then after getting them all working changed the R=302 to R=301 to make the redirects permanent.

Resources