【问题标题】:CodeIgniter routes not working with subdomainCodeIgniter 路由不适用于子域
【发布时间】:2016-03-28 19:10:55
【问题描述】:

我有转移到子域的 CodeIgniter 应用程序:customer.domain.com/application-name/

现在当我访问上面的 URL 时,我可以看到登录页面和图片链接等工作。

但是,路由不起作用。它返回一个 500 服务器错误,因为它试图做的是访问:

customer.domain.com/customer/class/method

如您所见,子域以某种方式附加到 url。这不应该是这样。应使用配置的基本路径。所以我希望它可以访问:

customer.domain.com/application-name/class/method

.

我觉得我需要在我的 .htaccess 文件中添加一些内容,但我不太确定该怎么做。

我的 config.php 文件:

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

$route['welcome'] = 'pub/welcome';
$route['send_new'] = 'pub/send_new';
$route['cron'] = 'pub/cron';
$route['invitation/(:any)'] = 'pub/invitation/$1';
$route['unsubscribe/(:any)'] = 'pub/unsubscribe/$1';
$route['widget/(:any)'] = 'pub/widget/$1';
$route['excel-tpl'] = 'pub/excel_tpl';
$route['pub/(:any)'] = 'pub/$1';
$route['pub/(:any)/(:any)'] = 'pub/$1/$2';
$route['(:any)'] = 'pub/short_url/$1';

我的 .htaccess 文件:

RewriteEngine on
RewriteRule \.(js|css)$ - [L]

RewriteCond    %{REQUEST_FILENAME}    !-f 
RewriteCond    %{REQUEST_FILENAME}    !-d 
RewriteRule    ^(.*)$ index.php?$1 [QSA,L]

希望大家能帮帮我。

【问题讨论】:

  • 检查 application/config/config.php 中 $config['base_url'] 的值并确保它是正确的。
  • 它是:'customer.domain.com/application-name' 所以这应该不是问题。
  • baseurl 应该以 http 或 https 开头...或者您可以尝试将其留空并查看是否可以解决问题。
  • 我都试过了。不会改变任何东西。

标签: php .htaccess codeigniter routing subdomain


【解决方案1】:

尝试添加

RewriteEngine on
RewriteRule \.(js|css)$ - [L]

RewriteCond %{HTTP_HOST} !^customer\.domain\.com [NC]
RewriteRule ^(.*)$ http://customer.domain.com/$1 [L,R=301]

RewriteCond    %{REQUEST_FILENAME}    !-f 
RewriteCond    %{REQUEST_FILENAME}    !-d 
RewriteRule    ^(.*)$ index.php?$1 [QSA,L]

.htaccess 文件。

【讨论】:

  • 不幸的是它并没有改变任何东西:(
  • 您发布了 routes.php,而不是 config.php 文件。注意优先级。 pub/(:any)/(:any) 必须在 pub/(:any) 之前。
猜你喜欢
  • 2015-07-08
  • 1970-01-01
  • 2014-02-26
  • 2015-08-11
  • 1970-01-01
  • 2013-03-11
  • 2018-03-16
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多