我在 Codeigniter 中使用路由来获取指向我的页面的干净整洁的 URL。我还修改了 htaccess 文件以从 URL 中删除 index.php。
除了 1 个问题之外,一切都工作得很好 - 当我转到某个 URL 时,它不会加载 CSS 或图像,除非将尾随/添加到 URL 中。
例如:
mysite.com/blah 不起作用
mysite.com/blah/ 有效
.htaccess 文件中可能有什么内容?这是我的文件:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|user_photos|favicon|robots\.txt)
RewriteRule ^(.*)$ /subdirectory/index.php/$1 [L]
有什么想法吗?当然,我希望用户即使不添加尾随/也能够访问该页面
最佳答案
使用<?php echo base_url();?>
在你的 CSS URL 前面
示例:
<link rel="stylesheet" href="<?php echo base_url();?>theme/css/main.css" />
至于.htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /subdirectory/index.php/$1 [L]
RewriteCond $1 !^(index\.php|includes|theme|media|robots\.txt|fonts)
关于.htaccess - 网站不会使用 Codeigniter 加载没有尾随/后 URL 的 CSS 或图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8835268/