我已经启用了mod_rewrite,并且正在使用.htaccess文件通过index.php传递所有请求。
如果我访问URL
http://localhost/mysite
http://localhost/mysite/abc页面只加载一次。
但是,如果我向路径添加额外的部分,页面会加载三次,并且我的css文件也不会包括在内:
http://localhost/mysite/abc/xyz
http://localhost/mysite/abc/xyz/ttt等等。
所有这些都会导致页面加载三次。我可以看到这一点,因为我在index.php中的Eclipse中设置了一个断点。
这是我的.htaccess文件:
<IfModule mod_rewrite.c>
RewriteEngine on
# Block access to "hidden" directories whose names begin with a period.
# Files whose names begin with a period are protected by the FilesMatch directive
# above.
RewriteRule "(^|/)\." - [F]
# Pass all requests not referring directly to files in the filesystem to
# index.php. Clean URLs are handled in drupal_environment_initialize().
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>知道为什么页面被多次加载而css丢失了吗?
发布于 2012-08-09 14:39:46
我相信RewriteRule ^ index.php是因为空间的问题。
试一试:
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]RewriteRule模式替换标志
模式:是请求文件index.php
替代:无(-意思是不替换)
标志:l-最后一个(不要再做了)
Condition1:如果请求的文件不存在
Condition2:如果请求的文件不是目录
应用下一个重写规则
RewriteRule模式替换标志
模式:任何东西
替代: /index.php
旗子:L-最后(不要再做了)
跳转到/index.php
因此,总结如下:
如果请求的文件是index.php确定的(并停止处理任何规则)
否则
如果文件存在,请执行
如果文件是目录,请进入该目录。
否则
跳转到根目录中的index.php
发布于 2015-09-17 07:13:13
我想添加我的情况作为补充信息。我发现这个答案也解决了我的问题。
我遇到的问题完全一样。我执行了db insert,并注意到条目被插入了随机次数。
有时15,有时2,有时25。
我必须改变的路线是:
RewriteRule (.*) core/$1 [L]到
RewriteRule (.*)core/$1 [L]因此,在(.*)核心/$1之间是一个空格,应该删除它。
https://stackoverflow.com/questions/11885760
复制相似问题