【问题标题】:.htaccess Redict URLs without File Extensions.htaccess 不带文件扩展名的重定向 URL
【发布时间】:2012-04-27 04:02:02
【问题描述】:
mit .htaccess 看起来像这样。
RewriteEngine on
RewriteRule !\.(js|gif|css|jpg|png|ico|txt|html)$ index.php [L]
它允许正常访问具有所列文件扩展名的 URL。所有其他请求都发送到 index.php。
如何简化我的 .htaccess,使其允许所有文件请求,并且仅将没有文件扩展名的请求重定向到 index.php?
【问题讨论】:
标签:
.htaccess
mod-rewrite
web
【解决方案1】:
我会这样做:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
我假设您的 .htaccess 位于您的文档根目录中。否则尝试:
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
这两个示例都会将所有流量发送到 index.php,但物理现有文件除外。