首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >启用mod_rewrite时多次加载页面(缺少css )

启用mod_rewrite时多次加载页面(缺少css )
EN

Stack Overflow用户
提问于 2012-08-09 14:33:12
回答 2查看 647关注 0票数 0

我已经启用了mod_rewrite,并且正在使用.htaccess文件通过index.php传递所有请求。

如果我访问URL

代码语言:javascript
复制
http://localhost/mysite

http://localhost/mysite/abc

页面只加载一次。

但是,如果我向路径添加额外的部分,页面会加载三次,并且我的css文件也不会包括在内:

代码语言:javascript
复制
http://localhost/mysite/abc/xyz

http://localhost/mysite/abc/xyz/ttt

等等。

所有这些都会导致页面加载三次。我可以看到这一点,因为我在index.php中的Eclipse中设置了一个断点。

这是我的.htaccess文件:

代码语言:javascript
复制
<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丢失了吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2012-08-09 14:39:46

我相信RewriteRule ^ index.php是因为空间的问题。

试一试:

代码语言:javascript
复制
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

票数 5
EN

Stack Overflow用户

发布于 2015-09-17 07:13:13

我想添加我的情况作为补充信息。我发现这个答案也解决了我的问题。

我遇到的问题完全一样。我执行了db insert,并注意到条目被插入了随机次数。

有时15,有时2,有时25。

我必须改变的路线是:

代码语言:javascript
复制
RewriteRule    (.*) core/$1    [L]

代码语言:javascript
复制
RewriteRule    (.*)core/$1    [L]

因此,在(.*)核心/$1之间是一个空格,应该删除它。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/11885760

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档