我有一种情况,我需要在文件存在时进行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
如何使用重写?
谢谢!
答案 0 :(得分:1)
您可以在DOCUMENT_ROOT/.htaccess
文件中尝试此规则:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.+?)/?$ /$1.html [L,R=302]