Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a Drupal 5.x based travel review site which I'm moving over to Wordpress 3.x (same domain name).

The Drupal site is structured like this:

  • www.example.com/travel-guides (these are top-level pages) - these are only a handful.
  • www.example.com/<filename>.html (filename is the name of a place / attraction etc). - makes up for bulk of the content in the site.

In WordPress the setup is fairly straightforward. All content follows a simple permalink:

www.example.com/postname

How do I set a rule in .htaccess to bulk redirect all the pages? There are over 600 pages and I don't want to manually set redirect rules for all of them.

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Above the WordPress rewrite rules add:

RedirectMatch permanent ^/([^/]+)\.html$ /$1

That will catch example.com/foo.html but not example.com/travel-guides/foo.html. To catch all URLs ending with .html remove the first ^ from the pattern.

To redirect all URLs ending with .html except those in travel-guides you need mod_rewrite:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_URI} !^/travel-guides/
RewriteRule ([^/]+)\.html$  /$1 [L,R=301]
share|improve this answer
    
Thanks toscho. Will implement that. But how do I set redirects for URLs within a folder but not example.com/travel-guides/foo.html. I'm not too familiar with coding but usually follow DIY guides. So this would be a 301 redirect right? –  user10718 Oct 20 '12 at 10:01
    
@user10718 See my update. Both rules send a 301. –  toscho Oct 20 '12 at 10:11
    
thanks!I'll try this and report back here –  user10718 Oct 20 '12 at 14:26
add comment

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.