简体   繁体   中英

htaccess rewrite rule for changing html and htm extensions to php

I am changing a website that has some pages ending with .htm and some pages ending with .html into php.

All site names, folders and structures remain the same and only the extension will change from .htm and .html to .php.

What would be the correct rewrite rule for the .htaccess file be in this regards?

After some research I came up with the following and want to make sure that this would be correct:

RewriteRule ^(.*).htm /$1.php [R=301,L]
RewriteRule ^(.*).html /$1.php [R=301,L]

Would above code in the .htaccess file be correct and is there something else I would have to include?

Your rules look fine, but you will have to turn the rewrite engine ON first..

RewriteEngine On

Then add your rules:

RewriteRule ^(.*)\.htm /$1.php [R=301,L]
RewriteRule ^(.*)\.html /$1.php [R=301,L]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM