【问题标题】:Codeigntier: Default route isn't calling "en" routeCodeigniter:默认路由不调用“en”路由
【发布时间】:2016-10-30 11:07:36
【问题描述】:

我正在从事 CI 项目,我在默认控制器之前调用“en”路由。但这似乎不起作用,我必须提供论据。

它的作用是:

http://193.42.156.121/airport/en

但我正在努力让它工作,即使是:

http://193.42.156.121/airport

我的路由配置在本地服务器上运行良好,但在基于 linux 的在线服务器上运行不一样。这是路由配置:

$route['default_controller'] = "auth";  
$route['404_override'] = '';

// example: '/en/about' -> use controller 'about'
$route['^fr/(.+)$'] = "$1";
$route['^en/(.+)$'] = "$1";
$route['^pt/(.+)$'] = "$1";
$route['^de/(.+)$'] = "$1";
$route['^ru/(.+)$'] = "$1";
$route['^tr/(.+)$'] = "$1";
 
// '/en' and '/fr' -> use default controller
$route['^fr$'] = $route['default_controller'];
$route['^en$'] = $route['default_controller'];
$route['^pt$'] = $route['default_controller'];
$route['^de$'] = $route['default_controller'];
$route['^ru$'] = $route['default_controller'];
$route['^tr$'] = $route['default_controller'];

或者如果我的 .htaccess 文件有任何问题?我不知道这是我的 .htaccess 文件:

RewriteEngine On
RewriteCond $1 !^(index\.php|styles|scripts|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1

【问题讨论】:

  • 检查控制器文件名和类确保只有第一个字母是大写示例:Auth.phpclass Auth extends CI_Controller
  • 刚刚检查过,一切都在它的位置。一旦我们给出“ /en ”,它就会正确浏览所有站点,而且这个项目是在 CI 2.0
  • 另一件事我没有使用 CI 的默认类,我有一个名为 MY_Controller 的不同类,我正在扩展它

标签: .htaccess codeigniter routes


【解决方案1】:
<IfModule mod_rewrite.c>
AddDefaultCharset UTF-8
  RewriteEngine On
  # !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
  #  slashes.
  # If your page resides at
  #  http://www.example.com/mypage/test1
  # then use
  # RewriteBase /mypage/test1/
  RewriteBase /mypage/
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don't have mod_rewrite installed, all 404's
  # can be sent to index.php, and everything works as normal.
  # Submitted by: ElliotHaughin

  ErrorDocument 404 /index.php
</IfModule>

【讨论】:

    【解决方案2】:

    有时事情会变得非常令人毛骨悚然,在通过查看源页面花了几个小时在这个问题上之后,我看到文档头部有一个换行符。通过从根目录中的 index.php 中删除第 1 号空行,它很好地显示了一些警告,我让它工作了。

    【讨论】:

      猜你喜欢
      • 2013-10-22
      • 2013-05-11
      • 2016-01-18
      • 2016-03-27
      • 2017-01-19
      • 1970-01-01
      • 2019-08-24
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多