Redirect Website Homepage Only - .htaccess

I have two different websites that are hosted on different servers. I would like to redirect the homepage of the old site (www.oldsite.com.au) to the homepage of the new site (newsite.com.au). However, I do not want any pages within the old site (www.oldsite.com.au/page) to redirect to the new one (newsite.com.au/page). So, www.oldsite.com.au must redirect to newsite.com.au, but any other pages or files within the old site must not redirect.
All the .htaccess ideas I've tried just redirect every file from the old site to the new one.

Try one of these:
RedirectMatch 301 ^/$ http://newsite.com.au/
or
RewriteEngine On
RewriteRule ^$ http://newsite.com.au/ [L,R=301]
If you don't want a 301 (permanent) redirect, remove the 301 from the RedirectMatch or the =301 from the square brackets in the rule's flags.

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.

301 redirect isn't working

I have a blog that I'm trying to redirect to a different domain.
Old domain: http://harrisonfjord.com
New domain: http://agoodman.com/blog/
Google states that you should do 301 redirection for all pages, so I took a list of urls from my XML sitemap and just manually set up the redirection.
Here's what I've put in my .htaccess file: http://pastebin.com/PkKNbJKf
The file structure is the same across both domains, so I can simply redirect each page as follows:
redirect 301 http://harrisonfjord.com/ http://agoodman.com.au
redirect 301 http://harrisonfjord.com/whatever http://agoodman.com.au/blog/whatever
However, this currently isn't working. Do I need to put the redirection in an tag or something?
What if you redirect your old-domain to new new domain completely?
# redirect an entire site via 301
redirect 301 / http://agoodman.com/blog/
Also try using RewriteEngine as:
RewriteEngine On
RewriteRule ^(.*)$ http://agoodman.com/blog/$1 [R=301,L]

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]

Redirect all but some to new URL?

I am moving site and I want to do a 301 redirect on all but some of the URLs,
Like this:
oldsite.com/* -> www.newsite.com
oldsite.com/specific/article/to/redirect -> www.newsite.com/fancy/blah
So there are a few things I want to redirect to specific pages but all the rest should just goto root, how can this be done in .htaccess?
Add the following to the .htaccess file in the root directory of your old site.
#place your specific redirects first
Redirect 301 /specific/article/to/redirect http://www.newsite.com/fancy/blah
RewriteEngine on
#then your general redirect all to new site last
RewriteRule ^ http://www.newsite.com%{REQUEST_URI} [L,R=301]
There's RedirectMatch if you've got only one URL that needs to be exempted.
RedirectMatch permanent !/specific/article/to/redirect http://www.newsite.com
for multiple URLs, you'd probably be better off with mod_rewrite and an external rewritemap that lists the urls to be exempted.

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