【问题标题】:Codeigniter routes not working when /css or /js in the url当 /css 或 /js 在 url 中时,Codeigniter 路由不起作用
【发布时间】:2017-08-12 19:51:43
【问题描述】:

我已将路线设置为

$route['(:any)'] = 'category/view/$1';

它每次都有效,除非 URL 包含 mysite.com/css 或 mysite.com/js。

我想要mysite.com/css这样的网址,我该怎么办??

谢谢。

【问题讨论】:

  • 确保你已经在 config.php 中设置了你的基本 url

标签: php codeigniter


【解决方案1】:

htaccess 规则所以你会尝试

<IfModule mod_rewrite.c>
 ReWriteEngine On
 RewriteCond $1 !^(index\.php|resources|assets|robots\.txt)
 ReWriteCond %{REQUEST_FILENAME} !-f
 ReWriteCond %{REQUEST_FILENAME} !-d
 ReWriteRule ^(.*)$ index.php/$1 [L]
</IfModule>

您可能只想删除扩展程序,以便这部分可以完成

【讨论】:

    【解决方案2】:

    我将假设这些是静态文件的 URL,而不是动态生成的 Javascript 或 CSS 文件。这意味着这些 URL 根本不需要点击 Codeigniter。我不知道您使用的是哪个 Web 服务器,但大多数(如果不是全部)都可以配置为将这些 URL 路由到静态文件夹,并且永远不会接触您的 PHP 引擎。还可以节省您的资源。

    这是一个关于如何在 Nginx 中执行此操作的链接:Serving Static Content - Nginx

    对于 Apache,这里也有回答:Apache not serving static content correctly

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-04
      相关资源
      最近更新 更多