htaccess的:重定向仅.html文件到网站根目录 [英] htaccess: redirect only .html files to website root

查看:207
本文介绍了htaccess的:重定向仅.html文件到网站根目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近升级的静态站点到CMS,我想老网站的所有html文件重定向到该站点的根目录(http://www.url.com),而不会影响CMS PHP。

I've recently upgraded a static site to a CMS and I'd like to redirect all the html files of the old site to the site's root (http://www.url.com), without affecting the CMS' PHP.

目前htaccess的看起来像这样

Current htaccess looks like this

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

显然,无论新规则我想补充不得与此相冲突。

Obviously whatever new rules I add mustn't conflict with this.

我想旧文件(url.com/page.html)重定向到url.com。

I'd like old files (url.com/page.html) to redirect to url.com.

我试图寻找,但没有任何工程之后的几件事情。任何帮助AP preciated。

I've tried a few things after searching but nothing works. Any help appreciated.

推荐答案

您需要将之前您的CMS规则添加这些规则

You need to add these rules before your CMS rules:

RewriteEngine On

# check that the request isn't for a legitimate existing resource
RewriteCond %{REQUEST_FILENAME} !-f

# redirect the .html request to the site root
RewriteRule ^(.*)\.html$ / [L,R=301]

这篇关于htaccess的:重定向仅.html文件到网站根目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆