.htaccess make subdomain the main domain without moving - .htaccess

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/

Related

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.

Permanent redirecting to different domain via .htacces

I got two domains. Lets say dom.com and dom.net.
Now I got alias on dom.net to dom.com, so when I come to dom.net it shows me dom.com - this is set on admin's webpage.
But I need when somebody comes from dom.net redirect him to dom.com/test/example.html.
My .htacces file is blank now.
Is it possible to do this using .htacces and how can it be done?
I got it!
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} dom.net$
RewriteRule ^(.*)$ http://www.dom.com/test$1 [R=301,L]
this code redirect me to test folder but still don't know how to redirect to .html page

How to do a 301 redirect using Coldfusion from www to http

I did one of these online SEO analysis checks on a website I am building. One of the issues identified is:
WWW redirection (301): no
For search bots website addresses with www and without it are considered as different pages. Adding redirection help you avoid double content panelty.
In my current .htaccess file I have the following:
# lose the www
RewriteCond %{http_host} ^www\.example\.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [R=301,NC]
I am not sure if the issue identified relates to the .htaccess file or something else?
I am using Coldfusion and all the searches I have done refers to 301 redirection but it seems that this relates to specific pages that need to be permanently redirected?
The code that I have found for Coldfusion 301 redirection is the following:
<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="http://www.example.com/coldfusion/tutorial">
<cfabort>
My question is how do I set up the 301 redirection as identified above? Do I add the coldfusion 301 redirection as per the code above, and if so how do I use it to redirect users from www.example.com to http://example.com?
Or, must this be done in the .htaccess file and how should I structure it?
Hope this is clear?
So, in summary, how do I fix this problem:
WWW redirection (301): no
For search bots website addresses with www and without it are considered as different pages. Adding redirection help you avoid double content panelty.
The method was not correct. This is the correct way to redirect from www to http.
RewriteEngine on
# lose the www
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
It is working perfectly now.

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

Need .htaccess assistance

We have an existing site, let's call it ourdomain.com. We moved content over from a site that is shutting down, let's call it legacydomain.com. We pointed the legacy domain at our server to the /public_html/ folder.
What I need is an .htaccess that will redirect legacydomain.com or legacydomain/anything-here to ourdomain.com/legacydomain/ with nothing else appended to the URL.
However, I also need a few specific URLs to redirect to certain destinations, and they don't really follow a pattern. For example:
legacydomain.com/something.html to ourdomain.com/legacydomain/something.html
legacydomain.com/another.html to ourdomain.com/legacydomain/folder/another.html
This is what I have tried:
RewriteCond %{HTTP_HOST} ^www\.legacydomain\.com$ [NC]
RewriteRule (.*) http://www.ourdomain.com/legacydomain/$1 [R=301,L]
Redirect 301 /something.html http://www.ourdomain.com/legacydomain/another.html
It mostly works, but if I visit legacydomain.com/anything-here it doesn't even attempt to rewrite, it just keeps the domain the same and gives a 404. And also I have a feeling that even if it did work, something like legacydomain.com/anything-here/more-stuff would get rewritten as ourdomain.com/legacydomain/anything-here/more-stuff which I don't want.
Only other thing in the .htaccess is rewriting non-www to www, and the standard WordPress stuff. Any guidance would be greatly appreciated. Everything above should have an http:// and www in front for the examples, but it wouldn't let me post that many "links".
For each specific rewrite you would need two lines, as follows. Depending on your existing config you may need to add a slash at the beginning of the RewriteRule in front of something.html if this doesn't work.
RewriteCond %{HTTP_HOST} legacydomain.com
RewriteRule something.html http://ourdomain.com/legacydomain/something.html [R=301,L]
Then you would use a catch-all for everything else.
RewriteCond %{HTTP_HOST} legacydomain.com
RewriteRule (.*) http://ourdomain.com/legacydomain/ [R=301,L]
Personally, I would go for the simplest solution which doesn't use mod_rewrite. First, just redirect the specific pages to wherever they need to go.
Redirect 301 /something.html http://ourdomain.com/legacydomain/something.html
Redirect 301 /another.html http://ourdomain.com/legacydomain/another.html
Then, simply redirect everything else to the base URL.
RedirectMatch 301 (.*) http://ourdomain.com/legacydomain/
These must be put in your .htaccess file before the RewriteEngine on statement.

Resources