【问题标题】:Putting Slash / in the URL in Codeigniter breaks the page style/images etc在 Codeigniter 的 URL 中放置斜杠 / 会破坏页面样式/图像等
【发布时间】:2019-12-07 10:41:05
【问题描述】:

我的网站运行良好。 所有控制器都可以正常工作,除非我在页面中断的末尾加上斜线。

这里是原始网址:Saaf.Pk

但是当我在最后加上一个斜线时,样式和图像就坏了:Here

我知道问题在于 URL 路径已更改。但是这种情况的一般解决方案是什么?

我的 .htaccess

<IfModule mod_rewrite.c> 
   RewriteEngine On
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ /index.php/$1 [L]
</IfModule>

【问题讨论】:

标签: codeigniter codeigniter-3 backslash trailing-slash


【解决方案1】:

您是否使用 base_url 来定义每个图像、js、css 等?

示例图片

<img src="<?=base_url('assets/uploads/cms/') . $cms->logo_2?>" alt="Logo">

示例js

<script src="<?=base_url('assets/plugins/jquery-3.3.1/jquery.min.js')?>"></script>

示例css

<link href="<?=base_url('assets/guide/css/hopscotch.css')?>" rel="stylesheet"/>

【讨论】:

    【解决方案2】:

    首先,在application->cofig->config.php中的config文件夹config.php位置设置base_url,使用as $config['base_url'] ='https://saaf.pk/';

    比给出图片、css和js的链接为">

    不要忘记在 autoload.php 文件中使用帮助 URL。

    【讨论】:

    • 让我试试这个,我会更新你的。谢谢。 @kapil。
    猜你喜欢
    • 2011-03-15
    • 1970-01-01
    • 2014-02-25
    • 2018-05-30
    • 1970-01-01
    • 2010-09-23
    • 1970-01-01
    • 2013-01-15
    • 2015-10-19
    相关资源
    最近更新 更多