Avoid Too Many Redirects on Root level 301 - .htaccess

I'm attempting to change the .htaccess on a website such that each page redirects to a specific page on another website. I've managed to get the non-root level pages to redirect to the new domain with no problem, but however I seem to try to redirect from the root of the old website I end up getting a 'too many redirects' problem. This feels pretty key for optimizing someone's site when they've changed from a previous domain, so would be useful to know.
The code I've got working is this:
Redirect 301 /my_counselling.html newsite.org.uk/
Redirect 301 /fees_and_contacts.html newsite.org.uk//?page_id=11
Redirect 301 /qualifications.html newsite.org.uk/
Redirect 301 /resources.html newsite.org.uk/
Redirect 301 /abuse.html newsite.org.uk/
Redirect 301 /drug_and_alchol.html newsite.org.uk//?page_id=57
Redirect 301 /lgbt_sexuality.html newsite.org.uk//?page_id=13
Redirect 301 /dyslexia.html newsite.org.uk//?page_id=8
But the following attempts to match the ROOT level all fail:
Redirect 301 / newsite.org.uk/
or
RewriteRule oldsite.com/ newsite.org.uk [R=301,L,NC]
or
RedirectMatch 301 ^/ newsite.org.uk/
which are suggestions I've read.
This feels like it should be very simple. If I can just get visitors and bots that would have gone to the old site's root to now go to the new site's root I'll be done.
Thanks so much!

It looks like both domains are on the same server, in that case, You'll need to match against the olddomain using a RewriteCondition and then redirect to the newdomain if that condtion is true.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain.uk$
RewriteRule ^(.*)$ http://www.newdomain.uk/$1 [NC,L,R=301]

Related

How to permanently redirect to new domains startpage?

If I wan't to redirect the whole site (from all pages) http://myoldsite.com to http://mynewsite.com I add this to myoldsites .htaccess:
RewriteEngine On
RewriteRule ^(.*)$ http://mynewsite.com/ [R=301]
That works fine, every page now goes to http://mynewsite.com.
But there is a problem, http://myoldsite.com/apage will go to http://mynewsite.com/apage. I wan't all pages to redirect to mynewsites startpage (http://mynewsite.com).
How can I do this?
Why on earth are you trying to do a permanent redirect with a rewrite rule?
RedirectMatch 301 ^/ http://example.com
It's called a permanent redirect for a reason. The code 301 isn't for your average user, it's for search engines.
EDIT: Redirect 301 / http://domain.com redirects to a new location, but it also takes consideration for anything you've typed after the basic domain, for example a folder.
What you need to use is RedirectMatch 301 ^/ http://example.com which will redirect everything to http://example.com.

htaccess redirect issue in godaddy

I have a htaccess which will redirect all subdomain to parent domain except one domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.theonlytutorials\.com$ [NC]
RewriteCond %1 !^(blog|www)$ [NC]
RewriteRule ^(.*)$ http://theonlytutorials.com/$1 [L,R=301]
This code was working fine in my previous hosting. But in Godaddy it doesn't seems to be working.
It is redirecting, but to the exact hosting location.
One of my URL structure:
www.theonlytutorials.com/video/58/4496/ChessBaseGmbH
Instead it is redirecting to:
www.theonlytutorials.com/others/tutorials/video/58/4496/ChessBaseGmbH
Where others / tutorials are the folders created in my hosting
On Go Daddy (and probably some other Hosts) the site folder names should be included in your redirect code.
RedirectMatch 301 ^/site-folder-name/video/58/4496/ChessBaseGmbH/$ http://the full URL here where you want the redirect point to
If you wanted to redirect a link from the /blog/ folder / site to another site
RedirectMatch 301 ^/blog/video/58/4496/ChessBaseGmbH/$ http://the full URL here where you want the redirect point to
Let's say you want to do a redirect from a site that is in this folder /others/ and you want to redirect to your root domain.
RedirectMatch 301 ^/others/video/58/4496/ChessBaseGmbH/$ http://the full URL here to your root domain where you want the redirect to point to
And logically the same thing would probably be true if you have this folder structure /others/another-nested-folder/
RedirectMatch 301 ^/others/another-nested-folder/video/58/4496/ChessBaseGmbH/$ http://the full URL here to your root domain where you want the redirect to point to

.htaccess - redirects after a certain point in the file not working

Would be so very grateful if someone can help me with this... I have been using a .htaccess 301 redirect file on my personal side business website for a while now however after a certain point in the file, the redirects simply do not work (returning a 200 in Rex Swain's http header tool).
I've looked through the file with a fine toothcomb and where the redirects stop working there are no issues at all (e.g. the urs are exactly as they should be). Really do not know why they would stop redirecting after a certain point?
Does anyone have any thoughts / recommendations? For anyone that would be willing to help I could send the file across.
Look forward to hearing from you,
Motley
Here's the code, the last line is the redirect that doesn't work. All before this work completely fine. There are other redirects after the last one (ive just not shown them), which also do not redirect. There is also a blank line at the end of the file.
.htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{http_host} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain/$1 [L,R=301]
Options +FollowSymLinks
RewriteEngine on
# index.html to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.html\ HTTP/
RewriteRule ^(.*)index\.html$ /$1 [R=301,L]
Redirect examples
Redirect 301 /spas/alexander-house/overnight-packages http://www.domain/spas/alexander-house/spa-breaks
Redirect 301 /spas/alexander-house/day-packages http://www.domain/spas/alexander-house/spa-days
Redirect 301 /spas/alexander-house/weekend-packages http://www.domain/spas/alexander-house/spa-weekends
Redirect 301 /spas/armathwaite-hall/overnight-packages http://www.domain/spas/armathwaite-hall/spa-breaks
Redirect 301 /spas/armathwaite-hall/day-packages.html http://www.domain/spas/armathwaite-hall/spa-days
Redirect 301 /spas/armathwaite-hall/weekend-packages http://www.domain/spas/armathwaite-hall/spa-weekends
Redirect 301 /spas/billesley-manor/overnight-packages http://www.domain/spas/billesley-manor/spa-breaks
Redirect 301 /spas/billesley-manor/day-packages http://www.domain/spas/billesley-manor/spa-days
Redirect 301 /spas/billesley-manor/weekend-packages http://www.domain/spas/billesley-manor/spa-weekends
Redirect 301 /spas/bishopstrow-house/overnight-packages http://www.domain/spas/bishopstrow-house/spa-breaks
Redirect 301 /spas/bishopstrow-house/day-packages http://www.domain/spas/bishopstrow-house/spa-days
Redirect 301 /spas/bishopstrow-house/weekend-packages http://www.domain/spas/bishopstrow-house/spa-weekends
Redirect 301 /spas/bovey-castle/overnight-packages http://www.domain/spas/bovey-castle/spa-breaks
Redirect 301 /spas/bovey-castle/day-packages http://www.domain/spas/bovey-castle/spa-days
Redirect 301 /spas/bovey-castle/weekend-packages http://www.domain/spas/bovey-castle/spa-weekends
Redirect 301 /spas/castlemartyr/overnight-packages http://www.domain/spas/castlemartyr/spa-breaks
Redirect 301 /spas/castlemartyr/day-packages http://www.domain/spas/castlemartyr/spa-days
Redirect 301 /spas/castlemartyr/weekend-packages http://www.domain/spas/castlemartyr/spa-weekends
Redirect 301 /spas/celtic-manor/overnight-packages http://www.domain/spas/celtic-manor/spa-breaks
Redirect 301 /spas/celtic-manor/day-packages http://www.domain/spas/celtic-manor/spa-days
Redirect 301 /spas/celtic-manor/weekend-packages http://www.domain/spas/celtic-manor/spa-weekends
Redirect 301 /spas/chewton-glen/overnight-packages http://www.domain/spas/chewton-glen/spa-breaks
Did you try moving the Redirect to a different line in the .htaccess file? If the redirects following the new line location of Redirect 301 /spas/chewton-glen/overnight-packages http://www.domain/spas/chewton-glen/spa-breaks aren't working now then you know it is this Redirect alone that is causing the problem. Did you try removing this one redirect and see if the preceding redirects now work? I bet it has something to do with the chewton-glen directory?

How to do 301 redirects with folders & subfolders?

I need to redirect all the old URLs on my site to new URLs, but am having issues. A given URL and its subfolders need redirecting to the same page.
For example, this is the first one:
redirect 301 /panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html
This works ok. However there are these size sub-pages which need to redirect to the same location:
redirect 301 /panache/sports-bra/30DD http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30E http://www.newdomain.co.uk/sports-bra.html
redirect 301 /panache/sports-bra/30F http://www.newdomain.co.uk/sports-bra.html
And these don't work, I end up at a location like the following:
http://www.newdomain.co.uk/sports-bra.html30DD
See the way the last part of the path is appended to the url? I'm guessing it's because the second redirect is conflicting with the initial 301 redirect?
I have also tried using this rewrite rule but have had no luck. The site is Magento so I don't know if this has some effect? mod_rewrite is enabled on the server.
RewriteRule ^panache/sports-bra/ http://www.newdomain.co.uk/sports-bra.html [R=301]
Any help mucha ppreciated.
Try this.
RewriteEngine on
RewriteRule ^(panache/sports-bra/.*)$ /sports-bra.html [L,R=301,NC]

301 redirect any page to one specific page

IS there a way with just htaccess 301 redirect to redirect any page on a domain to a specific page on another domain.
eg. I was domain.com/index.html and domain.com/contact.html to both redirect to newsite.com/index.html
But I am wanting to do this without having to list each of the pages specifically.
can my 301 redirect be just something like
301 * http://newsite.com/index.html
or how should it be set up. Unfortunately I don't have access to mod rewrite so I cant use mod rewrite to make it work.
Had an issue similar to this using wordpress and trying to remove all .asp extensions from pages, this worked pasted at the top of my .htaccess file
## 301 Redirects
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^(.*)\.asp$ $1? [R=301,NE,NC,L]
Yes, that is possible -- instead of mod_rewrite you need to use mod_alias (which has more chances to be enabled).
This one will redirect everything to index.html on newsite.com/
RedirectMatch 301 ^/(.*)$ http://newsite.com/index.html
This one will redirect everything to the same path but on another domain: (e.g. oldsite.com/meow.php => newsite.com/meow.php)
RedirectMatch 301 ^/(.*)$ http://newsite.com/$1

Resources