简体   繁体   English

htaccess重写规则,用于将html和htm扩展名更改为php

[英]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. 我正在将一个以.htm结尾的页面和以.html结尾的页面转换为php的网站。

All site names, folders and structures remain the same and only the extension will change from .htm and .html to .php. 所有站点名称,文件夹和结构均保持不变,只有扩展名将从.htm和.html更改为.php。

What would be the correct rewrite rule for the .htaccess file be in this regards? 在这方面,.htaccess文件的正确重写规则是什么?

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? .htaccess文件中的以上代码是否正确,是否还需要包含其他内容?

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]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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