htaccess html > php redirect + Wordpress rewrite permalinks structure

By : John
Source: Stackoverflow.com
Question!

I have started a site up using html only, switched it over to php to make my life easier and have used the following code in the .htaccess to ensure all users (who may have bookmarked) are still seeing the right pages:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.+)\.html$ http://domain.com/$1.php [R,NC]

Now I am working on the news section a wordpress blog (inside a /news directory) that would be lovely to use permalinks with, when I slap the rewrite code below into my .htaccess all my files outside of the wordpress directory default to wordpresses 404, they still have the correct address in the bar, but no information.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /news/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /news/index.php [L]
</IfModule>

Can anyone help on the correct structure for the .htaccess - I tend to use snippets for specific tasks rather than write htaccess stuff.

Thanks

By : John


Answers

Your rules have to be come before the Wordpress rules and you need to add an [L] to your RewriteRule:

RewriteRule ^(.+)\.html$ http://domain.com/$1.php [R,NC,L]

Which will tell .htaccess to stop processing rules.

I would recommend a permanent (301) redirect so Google and the other search engines will update their listings:

RewriteRule ^(.+)\.html$ http://domain.com/$1.php [R=301,NC,L]


This video can help you solving your question :)
By: admin