0

我已经启用mod_rewrite并且正在使用一个.htaccess文件来传递所有请求index.php

如果我访问 URL

http://localhost/mysite

http://localhost/mysite/abc

页面加载一次。

但是,如果我在路径中添加额外的部分,页面会加载 3 次,并且我的 css 文件不会被包含在内:

http://localhost/mysite/abc/xyz

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

ETC...

所有这些都会导致页面加载 3 次。我可以看到这一点,因为我index.phpEclipse中设置了断点。

这是我的.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?

4

2 回答 2

5

我相信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 : 如果请求的文件不存在

条件2:如果请求的文件不是目录

应用下一个重写规则
RewriteRule模式替换标志
模式:任何
替换:/index.php
标志:L - 最后(不要再做)
IE 跳转到 /index.php

所以总而言之:
如果请求的文件是 index.php 确定(并停止处理任何更多规则) ,
否则
如果文件存在,则执行
如果文件是目录,则进入该目录,
否则
跳转到根 web 目录中的 index.php

于 2012-08-09T14:39:46.530 回答
0

我想将我的情况添加为附加信息。我发现这个答案也可以解决我的问题。

我遇到的问题完全一样。我执行了一个数据库插入,我注意到该条目被插入了随机次数。

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

我必须改变的行是:

RewriteRule    (.*) core/$1    [L]

RewriteRule    (.*)core/$1    [L]

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

于 2015-09-17T07:13:13.777 回答