0

我正在尝试使用 htaccess 文件配置我的站点,以便重写任何以 .html 结尾的请求,以便新 URL 相同,但末尾不存在“.html”。无论请求可能有多少目录,这都应该有效。

例如, http ://site.com/page1.html -> http://site.com/page1

http://site.com/dir1/dir2/page2.html -> http://site.com/dir1/dir2/page2

http://site.com/~bob/dir3/page3.html -> http://site.com/~bob/dir3/page3

我更喜欢不需要对域名进行硬编码的解决方案,但如有必要,这是可以接受的。

我当前的 .htaccess 文件是一个标准的 Zend Framework .htaccess 文件,它工作正常。我知道如果我将站点移到其他地方,我将需要更改重写基础。

SetEnv APPLICATION_ENV development

RewriteEngine On

#Send all requests for non-existant files to index.php
RewriteBase /~rburk/refactor
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
4

1 回答 1

2

尝试将这些规则添加到文档根目录中的 htaccess 文件中:

RewriteEngine On

RewriteCond %{THE_REQUEST} \ /(.*)\.html($|\ )
RewriteRule ^ /%1 [L,R=301]

RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ /$1.html [L]
于 2013-09-17T16:43:35.687 回答