Regex HTACCESS强制具有html扩展名

Regex HTACCESS强制具有html扩展名,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我更改了我的CMS,现在我的URL除了index.html外没有.html结尾 我当前的.htaccess RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ includes/sitemap.php?datei=$1 [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^. index.ph

我更改了我的CMS,现在我的URL除了index.html外没有.html结尾

我当前的.htaccess

   RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ includes/sitemap.php?datei=$1 [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^. index.php [L]
我正在使用.htaccess的代码删除.html

RedirectMatch 301 (.*)\.html$ http://domain.com$1
编辑

我的旧URL如下所示,其中列出了404错误

http://domain.com/motor/servo.html
http://domain.com/arduino.html
我的新系统SEO生成的URL没有.html扩展名,一些主文件有.php扩展名

我可以用什么正则表达式来解决它


thx

您可以将此规则与负前瞻正则表达式一起使用:

RedirectMatch 301 ^((?!index)[^.]+)\.html$ http://domain.com/$1
编辑:根据修改后的问题,您可以使用此选项。htaccess:

RewriteEngine On
RewriteCond %{THE_REQUEST} \.html[?\s] [NC]
RewriteRule ^((?!index)[^.]+)\.html$ /$1 [L,NC,R=301]

RewriteRule ^((urllist|sitemap_).*\.(xml|txt)(\.gz)?)$ includes/sitemap.php?datei=$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^. index.php [L]

谢谢你的回复。这并没有解决我的问题。似乎索引希望保留php.html扩展名。不知道我现在应该用什么。我已经根据你修改的问题更新了我的答案。现在就试试。一个不起作用的问题。结果似乎是
http://domain.com/www/wordpress/arduino.html
。根文件夹添加在域和.html之间。