【问题标题】:Codeigniter, windows, xampp, how to use htaccess to get rid of trailing slash?Codeigniter、windows、xampp,如何使用htaccess去掉斜杠?
【发布时间】:2015-11-23 19:32:09
【问题描述】:

所以我使用了一个我在这里搜索过的 .htaccess 文件,我使用这个:

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

根据需要删除 index.php 文件。我在 codeigniter 目录中有 .htaccess 文件。使用带有斜杠的此链接可以正常显示网站:

http://localhost/codeigniter/home/

但是在 home.php 之后转到链接但没有斜杠显示我的网站看起来没有链接到 css 文件。有什么建议么?

另外,在我的config.php 文件中,我编辑了索引页:

$config['index_page'] = "";

如果这有什么不同的话。

【问题讨论】:

    标签: php apache .htaccess codeigniter


    【解决方案1】:
    RewriteEngine on
    
    # Next two lines get rid of trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.+)/$ $1 [L,R=301]
    
    RewriteCond $1 !^(index\.php|resources|robots\.txt)
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L,QSA]
    

    配置文件中的base_url也应该是

    $config['base_url'] = 'http://localhost/codeigniter/';
    

    您应该从视图文件中发布代码,让我们确定发生了什么。我假设您正在使用某种相对路径。尝试使用类似的东西:

    <link rel="stylesheet" type="text/css" href="<?php echo base_url('resources/css/main.css'); ?>">
    

    之前不要忘记加载 url helper。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-08-16
      • 1970-01-01
      • 1970-01-01
      • 2015-11-05
      • 2013-07-05
      相关资源
      最近更新 更多