Stephanie
Stephanie

Reputation: 71

Sitewide 301 Redirect

I am looking to perform a sitewide 301 redirect. The original site is over 15 years old! I understand the concept of making the .htaccess file with the code:

redirect 301 "/old/old.htm" http://www.you.com/new.html

However will this redirect every page of the old site? or just an individual page. How do I achieve redirection with the entire site?

Upvotes: 4

Views: 3562

Answers (5)

scgough
scgough

Reputation: 5252

Am I right in thinking that your site is on the same domain name but you've changed it structurally?
So, you have a load of old page URLs that have now changed to new URLs (but on the same domain).

For example, you may have had:
www.yourdomain.com/about-us/history.htm
that has now become
www.yourdomain.com/our-history.htm

If that is the case you will more than likely need to set up many 301 redirect rules. It doesn't necessarily mean that you have to set up one rule for every single page change as you can use RegEx to catch pattern changes in the URL structure. As a scale example, I recently set up a htaccess file of 301 redirects for a site with just under 600 changed URLs. There were 70-something 301 Redirect rules in the end.

It's not necessarily a small job but it is doable. Worth it to retain your SEO rankings.

Upvotes: 0

William
William

Reputation: 31

I have a rewrite in .htaccess (apache rewrite mod enabled), all pages from old site http://www.old.com and http://www.old.com/site/index.php? .... redirect to the new site http://www.new.com or http://www.new.com/website/index.php?... (notice that /site/ and /website/ are different names)

pages from the old site https://www.old.com (notice the s on https://) get redirected fine but pages from https://www.old.com/site/index.php?... do not, they get a 404 error

since the old site is not secure anymore neither the https://www.old.com or https://www.old.com/site/index.php?... really exist anymore but https://www.old.com gets redirected and the ones with /site/index.php?... added do not get redirected but go instead to a 404 error

Upvotes: 3

Sebastian
Sebastian

Reputation: 1429

Assuming the old pages don't exist any more (would throw 404-errors), you can do the following: You redirect all the pages that don't exist anymore to the start page. (As specified in the comments below.)

This is the updated .htaccess code you can use to make that happen. The first RewriteCond checks if the requested path is a file, the second checks if its a directory. After that, you get redirected to the startpage - or any other page for that matter.

http://www.example.com/i/am/an/old/page.html or http://www.example.com/i/am/a/different/old/page.html will all redirect to http://www.example.com/

RewriteEngine on
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . / [R=301,L]

Upvotes: 1

TheAlbear
TheAlbear

Reputation: 5595

Be careful with a 301, 301 redirect is used for where content has moved.

e.g. content about making a cake was here /makeacake.html now is /cakes/making-a-cake.html.

what I would recommend is find the pages where the majority of your uses come to, and redirect those pages to the new relevant pages / sections and just delete the rest and add a custom 404 error page. which tells them the old content has been moved.

You can also use goggle web masters to remove pages from there index.

Upvotes: 2

Flipster
Flipster

Reputation: 4401

The best way to redirect the entire site is by doing domain forwarding through your web server (or web host... most have the option in their control panel).

Domain forwarding is much more efficient than sending 301 redirects back to the client.

Upvotes: 0

Related Questions