RewriteRule没有按预期工作?

时间:2013-08-16 16:20:38

标签: .htaccess

我正在尝试实现前端控制器。所以我想将请求重定向到index.php。这是我的.htaccess。


RewriteEngine On

# Redirect everything to the Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^(css|images|files)/ index.php [NC,L]

<小时/> 目前,如果我访问以下网址,则可以:

http://devserver/myapp/

但是,如果我访问任何无法解析为index.php的网址,例如http://devserver/app/blog,Apache会告诉我它无法找到index.php:


  

请求的网址   的 /absolute/path/to/myapp/index.php   在这台服务器上找不到。


但是这条路径实际存在于我的服务器上,所以我认为正在发生的事情是Apache正试图像浏览器那样访问该URL - 并且它不起作用,因为如果我输入: 在我的浏览器中 /absolute/path/to/myapp/index.php ,它不起作用。所以,我决定将.htaccess中的最后一行更改为:

RewriteRule !^(css|images|files)/ http://myapp.com/index.php [NC,L]

但它仍然不起作用,因为现在当我在我的PHP代码中检查$_SERVER[REQUEST_URI]时, 总是 解析为index.php因为Apache提出了HTTP请求。

无论如何,有人可以告诉我我做错了什么,我能做些什么来让Apache将所有内容重定向到index.php?

谢谢,

1 个答案:

答案 0 :(得分:0)

不确定,但试试这个。

RewriteEngine On

# Redirect everything to the Front Controller
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
# RewriteRule !^(css|images|files)/ index.php [NC,L]
RewriteRule ^(.*)$ index.php/$1 [L]
相关问题