【发布时间】:2013-09-17 16:39:15
【问题描述】:
我正在尝试使用 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]
【问题讨论】:
-
这些 HTML 页面是否与您的 zend 框架相关?
-
我正在将现有站点转换为 Zend 框架。新页面没有 .html 扩展名,而现有页面有,所以我希望旧 URL 重定向到新 URL。
标签: apache .htaccess mod-rewrite