我需要一个重写规则,它会将每个请求重写为index.php
,除非单词web
在网址中。因此,每个图像,JS,CSS文件都位于Web文件夹下。这是我的.htaccess
文件,目前可以解决这个问题:
<IfModule mod_rewrite.c>
RewriteEngine On
# Folders / files to exclude from rewrite divided by Pipe goes here:
RewriteRule (^|/)web(/|$) - [L,NC]
# turn empty requests into requests for "index.php",
# keeping the query string intact
RewriteRule ^$ index.php [QSA]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !favicon.ico$
RewriteRule ^(.+)$ index.php [QSA,L]
RewriteRule ^(.+)$ index.php [QSA,L]
</IfModule>
这适用于:
http://localhost/~alpham8/application/index/index/
http://localhost/~alpham8/application/
http://localhost/~alpham8/application/index/someaction/
http://localhost/~alpham8/application/web/img/someimage.png
但它不起作用:
http://localhost/~alpham8/application/somecontroller/someaction/
无效URL会返回404错误。
请帮帮我。