Forum Moderators: phranque
I've picked through many .htaccess posts here and hacked around most of the night with no luck. I'm new to .htaccess rules.
I am migrating a live website from .html to Wordpress and want to send all requests from www.domain.com to www.domain.com/travel
I have put specific rules in .htaccess for each URL (about 40 total) that look like this:
RewriteRule ^site-map\.html$ /travel/site-map/ [R]
RewriteRule ^contact\.html$ /travel/contact/ [R]
and etc....
They work great, but after the 40 specific rules I need a simple catch all that will send anything else www.domain.com that I don't know about to www.domain.com/travel.
I've tried several different options and my catchall works great but ends up trashing the rules for the specific URLs I made before.
Any help is appreciated - cheers!
Did you read the Apache mod_rewrite documentation? It's a good idea, unless you like "trashing your site"... Using mod_rewrite without reading the instructions can be quite deadly to your server function, search results rankings, traffic, revenue, and business. See the resources cited in our Apache Forum Charter.
There is no need to use 40 rules if all you want to do is redirect all .html pages to a subdirectory and remove the trailing ".html". This problem could probably be handled by a single rule, possibly adding RewriteConds later if needed to create exceptions for special cases:
RewriteRule ^([^.]+)\.html$ http://www.example.com/travel/$1/ [R=301,L]
RewriteRule ^([^.]+)\.html$ http://www.example.com/travel/$1/ [R=301,L]
worked just fine after I removed the $1 at the end - perfect!
I agree, and wish I didn't have to use the individual rules, unfortunately during this migration many URLs are being changed for SEO so unlike my 2 examples they don't always match up to their .html equivalents.
I will keep an eye on the server and Apache. Thankfully, .htaccess should not require any more tinkering beyond this.
Thanks for your help!
- Greg