【问题标题】:$route['viewproduct/(:any)']='Product/viewproduct/$1'; will change my default directory path$route['viewproduct/(:any)']='Product/viewproduct/$1';将更改我的默认目录路径
【发布时间】:2018-03-07 13:03:47
【问题描述】:
$route['viewproduct/(:any)']='Product/viewproduct/$1';

将更改我的默认目录路径。我将路径设置为 https://baseurl/project/

但在我将所有 js &css href 中的路由路径更改为 https://baseurl/project/viewprodect 之后

【问题讨论】:

  • 您能否编辑问题并详细解释您的问题!

标签: php codeigniter routes


【解决方案1】:

我曾经遇到过同样的问题,我有两种情况:

场景一:

应用程序/config/config.php

config['base_url'] = '';  
//this should be defined as the page location, on localhost it should be
//localhost/TheAppFolder, or http://this.is.my.page 

如果是这种情况,那么base_url() 方法会获取浏览器 url 上写的内容,它会尝试从中获取 css 和 js

 http://this.is.my.page/something/MyCSSfile.css
 http://this.is.my.page/something/MyJSFile.js

如果在你的视图中你像这样调用 css 或 js,就会发生这种情况

<script src="../../MyJsfile.js" 
 type="text/javascript"></script>

<link href="../myCssFile.css" rel="stylesheet" type="text/css"/>

如何解决?

假设所有你的 css 和 js 都放在 public_html 文件夹上的文件夹名称 assets 上,所以到你的 css 和 js 文件的所有路由都类似于

../assets/js/myJsFile.js    //JS file
../assets/css/myCssFile.css //CSS file

在每个&lt;link&gt;&lt;script&gt; 标签上写成这样:

 <link href="<?=base_url()?>assets/css/myCssFile.css" rel="stylesheet" type="text/css"/>

 <script src="<?=base_url()?>assets/js/MyJsfile.js" type="text/javascript">    </script>

场景 2:

/applicationFolder/.htaccess 文件

我多次发现这个问题,解决方法是简单地将.htaccess文件内容更改为

 RewriteEngine on
 RewriteCond $1 !^(index\.php|resources|robots\.txt) 
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*)$ index.php/$1 [L,QSA]

【讨论】:

    【解决方案2】:

    将js & css路径改为

    <script src="<?php echo base_url();?>/js/jquery-2.1.1.min.js"></script> 
    <link href="<?php echo base_url();?>css/style.css" rel="stylesheet" type="text/css"  />
    

    【讨论】:

      猜你喜欢
      • 2017-12-05
      • 1970-01-01
      • 2017-12-19
      • 2021-07-20
      • 1970-01-01
      • 2012-03-18
      • 2013-09-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多