Jim*_*_CS 0 php apache .htaccess mod-rewrite url-rewriting
我已启用mod_rewrite
并使用.htaccess
文件传递所有请求index.php
.
如果我访问URL的
http://localhost/mysite
http://localhost/mysite/abc
Run Code Online (Sandbox Code Playgroud)
页面加载一次.
但是,如果我在路径中添加额外的部分,页面加载三次,我的css文件不包括在内:
http://localhost/mysite/abc/xyz
http://localhost/mysite/abc/xyz/ttt
Run Code Online (Sandbox Code Playgroud)
等等...
全部导致页面加载三次.我可以看到这一点,因为我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>
Run Code Online (Sandbox Code Playgroud)
任何想法为什么页面多次加载而css缺失?
我相信RewriteRule ^ index.php是因为空间的问题.
试试这个:
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
Run Code Online (Sandbox Code Playgroud)
RewriteRule模式替换标志
模式:请求文件index.php
替换:无( - 表示不替换)
标志:L - last (不再做)
条件1:如果请求的文件不存在
条件2:如果请求的文件不是目录
应用下一个重写规则
RewriteRule模式替换标志
模式:任何
替换:/index.php
标志:L - 最后(不再做)
IE跳转到/index.php
总结:
如果请求的文件是index.php OK(并停止处理更多规则)
否则
如果文件存在则执行
如果file是目录进入该目录,
否则
跳转到根web目录中的index.php
归档时间: |
|
查看次数: |
564 次 |
最近记录: |