Regex htaccess重写为add.html(如果存在),否则保持URL不变

Regex htaccess重写为add.html(如果存在),否则保持URL不变,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我有一个情况,我需要做一个URL重写,如果一个文件存在,否则留下的URL是原样 下面是一个例子: http://mydomain.com/section -> if http://mydomain.com/section exists go to -> http://mydomain.com/section.html http://mydomain.com/section -> if http://mydomain.com/section.html DOES NOT exist

我有一个情况,我需要做一个URL重写,如果一个文件存在,否则留下的URL是原样

下面是一个例子:

http://mydomain.com/section -> if http://mydomain.com/section exists go to -> http://mydomain.com/section.html
http://mydomain.com/section -> if http://mydomain.com/section.html DOES NOT exist go to -> http://mydomain.com/section
我如何用重写器来完成这项工作


谢谢

您可以在
文档\u ROOT/.htaccess
文件中尝试此规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ /$1.html [L,R=302]

您可以在
文档\u ROOT/.htaccess
文件中尝试此规则:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ /$1.html [L,R=302]

谢谢anubhava,但它并没有完全满足我的需要:(当我转到它时,我只希望它在不存在的情况下加载,而在我的情况下,它确实存在。再次感谢您,但您编写了:
http://mydomain.com/section ->存在?是->http://mydomain.com/section.html
我现在搞不清楚具体要求是什么。对不起,阿努巴瓦,我澄清了这个问题。当我说“去”时我的意思是,改变一下你的生活,但这并不是我所需要的:(当我转到它时,我只希望它在不存在的情况下加载,而在我的情况下,它确实存在。再次感谢您,但您编写了:
http://mydomain.com/section ->存在?是->http://mydomain.com/section.html
我现在搞不清楚具体要求是什么。对不起,阿努巴瓦,我澄清了这个问题。当我说“去”时我的意思是改变网址