Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

A client of mine scrapped his entire wordpress site of many years for a custom CMS. The URL structures both use the /<post_title> format, so a pattern based .htaccess rule is out of the picture for saving the old urls. The old site is effectively dead, but I'd hate to let all of those thousands of backlinks simply die a 404 death.

Is there a faster way than listing each url in a .htaccess directive to redirect 1000s of urls to the home page? (Faster as in load speed, not programming efficiency)

share|improve this question

3 Answers 3

up vote 2 down vote accepted

In your custom 404 page you could check the structure of the URL and 301-redirect if it looks good - or preferably look it up against a known list of previous Wordpress URLs.

At least this way you are only doing the lookup/redirect if the page doesn't exist.

If you are doing 1000s of redirects with Apache, it will be more efficient/faster to do this in your server config (vhost) files. Ref: Move .htaccess content into vhost, for performance

EDIT: I expect you've considered this already, but the thought was beginning to nag... do these missing pages have equivalent new URLs? Although a lot more work, it will obviously be many(*N) times better (for SEO and users) to redirect to the new URL if possible.

(Where N is a sufficiently large arbitrary number.)

share|improve this answer
    
That's a great idea. I didn't even think of capturing the 404 and only doing the url match then. I'll need to prevent the actual 404 header, but this is definitely the way to go. –  Dan Gayle Jun 14 '13 at 3:08
    
If you are using something like PHP's header function then simply stating an alternative Location header should be sufficient to replace the current 404. eg. header('Location: ...',true,301) –  w3d Jun 14 '13 at 8:33
    
Ideally these would all go to a new URL in a subdirectory where I set up a new WordPress install with updated permalinks. –  Dan Gayle Jun 14 '13 at 21:09

Have you thought about adding a string to the new URL's and then do a regex in Apache config to 301 redirect all URL's that don't match the string? You should certainly do 301 redirects to retain the value of the backlinks.

share|improve this answer

You can add "ErrorDocument 404 /404.php" to the .htaccess file and setup a php redirect on 404.php.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.