htaccess and 301 Redirect - .htaccess

I have want to redirect
http://old.clients.domain.com
to
http://clients.domain.com
In the htaccess file, I write a permanent redirect
Redirect 301 / http://clients.domain.com
When I type old.clients.domain.com, it changes the address to clients.domain.com in the address bar, but it does not give me the page, instead it gives me this in Firefox:
The page isn't redirecting properly
Firefox has detected that the server is redirecting the request for this address in a way that will never complete.
What do I do wrong? Thank you.

What's this? No wonder anyone who uses the example here is getting an Internal Server Error! =old.clients.domain.com is invalid.
Instead of
Rewritecond %{HTTP_HOST} =old.clients.domain.com
Use
Rewritecond %{HTTP_HOST} (www\.)?old.clients.domain\.com
So an example of the correct code would be
RewriteEngine On
RewriteBase /
Rewritecond %{HTTP_HOST} (www\.)?old.clients.domain\.com
RewriteRule ^.*$ http://new.clients.domain.com/$0 [R=301,L]
And this will work when redirecting the root domain to an addon domain and prevent errors like "Firefox has detected that the server is redirecting the request for this address in a way that will never complete"

I think it also returns 301 for http://clients.domain.com/
You must put .htaccess file only for directory for http://old.clients.domain.com/

If they point to the same root directory then the easiest way to do this is with a conditional rewrite statement in the root .htaccess file:
RewriteEngine On
RewriteBase /
Rewritecond %{HTTP_HOST} =old.clients.domain.com
RewriteRule ^.*$ http://clients.domain.com/$0 [R=301,L]
You need the guard to prevent re-redirection of valid clients.domain.com requests which most browsers, such as Ff, will pick up as an infinite redirect.

Related

HTACCESS Redirects and How to Properly Redirect to a domain to the Home Page

I have a domain: soloENEGYBAR.ca which is properly redirecting to soloNUTRITION.ca as long as it's http://
This does NOT WORK for https:// and errors (I do not know why).
THE GOAL
Is there a way to make it so the sub folders for soloenergybar.com ALSO redirect to the home page for solonutrition.ca? As well as get this to work for http:// and https:// instead of just http://
For example, right now if I go to: soloenergybar.ca/en/home it redirects to solonutrition.ca/en/home which doesn't exist!
I would like to know if there's a way to force EVERY URL combo from soloenergybar.ca to go to the home page of solonutrition.ca vs adding the additional folder tree info /en/home/?
Thank you!
Current HTACCESS setting:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^132\.148\.131\.136
RewriteRule (.*) "https://www.solonutrition\.ca\/$1" [R=301,L]
You may use this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} soloenergybar\.ca$ [NC]
RewriteRule ^ https://www.solonutrition.ca/? [R=301,L]
Make sure to clear your browser cache or test in a new browser to avoid old cache,

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.

redirect 301 not working properly in .htaccess

htaccess 301 redirect. I have this old site which is for example http://test.org/conference I want to redirect it to conference.test.org
What happened is the 301 redirect in my .htaccess file is quite buggy.
Here is my 301 redirect htaccess code below:
RewriteCond %{REQUEST_URI} ^/http://test.org/conference(/)?
RewriteRule ^(.*)$ http://conference.test.org/? [R=301,L]
When I test this one it runs and redirects correctly. But when I test it over and over again. It seems not to redirect anymore.
Can someone help me have a htaccess 301 redirect code?
Any help is much appreciated.TIA
I assume this is what you are looking for:
RewriteEngine on
RewriteRule ^conference/?$ http://conference.test.org/ [R=301,L,QSA]
Please note that %{REQUEST_URI} only contains the path of the URI, so not the protocol and the hostname. Reason is that the evaluation is performed inside a http host. This is explicitly pointed out in the documentation: http://httpd.apache.org/docs/current/mod/mod_rewrite.html
Depending on your http hosts setup you might also have to add a condition to prevent an endless redirection loop:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^conference\.test\.org$ [NC]
RewriteRule ^conference/?$ http://conference.test.org/ [R=301,L,QSA]
But usually that is not required, since the rule should be defined inside the test.org http host...

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

How to Permanent Redirect a Directory That No Longer Exists (via .htaccess)

I am having trouble redirecting an entire directory that no longer exists on our server.
All variations of the following are not working and I simply get a 404 Page Not Found.
.htaccess file looks like this:
redirect 301 /non_existent_directory/ http://my.website.com/existent_directory/
Is it possible to use the Redirect 301 directive for this? Or is this only solvable by mod_rewrite?
Thanks
I even tried:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?my\.website\.com\/non_existent_directory\/$ [NC]
RewriteRule ^(.*)$ http://my.website.com/existent_directory/ [R=301,L]
No luck...
From the Redirect documentation, I would say
Redirect 301 /non_existent_directory http://my.website.com/existent_directory
or
Redirect 301 /non_existent_directory /existent_directory
should work, provided you are allowed to use this in a .htaccess file. See also Troubleshooting .htaccess files. You should test without 301 though, to prevent caching of bad redirects by the client.
If this doesn't work, you can try a RewriteRule of course
RewriteEngine On
RewriteRule ^/?non_existent_directory(.*)$ /existent_directory$1 [R,L]
But this is equivalent to the above Redirect directive.

Resources