2012-04-26 215 views
0

mit .htaccess看起来像这样。.htaccess Redict URLs没有文件扩展名

RewriteEngine on 
RewriteRule !\.(js|gif|css|jpg|png|ico|txt|html)$ index.php [L] 

它允许正常访问列出的文件扩展名的URL。所有其他请求都发送到index.php。

我该如何简化我的.htaccess,以便它允许所有文件请求,并且只请求没有文件扩展名的请求到index.php?

回答

2

我会做这样的:

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

我假设你的.htaccess位于你的DocumentRoot。否则尝试:

RewriteEngine On 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f 
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

两个例子都将派遣所有的流量除了那些在物理上存在的文件到index.php。

+0

你的假设是正确的,第一个剪辑适合我!谢谢。 – danijar 2012-04-26 20:06:30