【问题标题】:routing issue in localhost in codeignitercodeigniter中本地主机的路由问题
【发布时间】:2017-06-02 19:33:06
【问题描述】:

我有这个 URL:http://localhost/fixbud/ 作为我的主页 URL。我的页面渲染良好。但是当我转到另一个链接时:http://localhost/fixbud/answer_forum 我收到错误 404。

这是我的路线:

$route['default_controller'] = "fixbudd";
$route['404_override'] = '';
$route['index'] = "fixbudd/index";
$route['answer_forum'] = "fixbudd/answer_forum";

.htaccess

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

配置

$config['base_url'] = 'http://localhost/fixbud/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

你能告诉我路由 URL 的规则以及如何解决我的问题吗? 我正在使用 CI2

【问题讨论】:

  • 可能是 url 重写问题
  • 你添加htaccess文件了吗?
  • 抱歉,我已经编辑了我的帖子并包含了我的 htaccess
  • 你能从这里访问你的网址吗:localhost/fixbud/index.php/answer_forum
  • 同时检查您的application/config.php 文件并检查$config['index_page'] 变量。如果你有 index.php 则删除它

标签: php codeigniter routes


【解决方案1】:

我遇到了同样的问题,将这个添加到 apache config 解决了它。

   <Directory "<to your project">

       Options Indexes FollowSymLinks MultiViews

       AllowOverride All

      Order allow,deny

      allow from all

      Require all granted

</Directory>

来源http://acmeextension.com/remove-index-php-in-your-codeigniter-project/

【讨论】:

    【解决方案2】:

    发生这种情况是因为 .htaccess 文件,我更喜欢为本地环境创建新的 .htaccess 文件并添加以下代码。

    RewriteEngine on
    
    RewriteCond $1 !^(index\.php|assets|images|js|css|uploads|favicon.png)
    
    RewriteCond %(REQUEST_FILENAME) !-f
    
    RewriteCond %(REQUEST_FILENAME) !-d
    
    RewriteRule ^(.*)$ ./index.php/$1 [L]
    

    【讨论】:

      【解决方案3】:

      更改$config['base_url'] = 'localhost/fixbud/';

      这个给

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

      您的呼叫将转到“fixbudd”控制器和方法“answer_forum”;

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-11-30
      • 1970-01-01
      • 1970-01-01
      • 2012-06-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多