【问题标题】:Codeigniter htaccess for localhost本地主机的 Codeigniter htaccess
【发布时间】:2015-08-08 03:00:39
【问题描述】:

我在使用 codeigniter 路由时遇到了一些问题。我在托管服务器中有一个实时站点,这是它的 htaccess。

#php_value memory_limit 256M
#php_value upload_max_filesize  50M
#php_value post_max_size  70M

AddType font/opentype .otf
AddType application/vnd.ms-fontobject .eot
AddType font/ttf .ttf
AddType application/font-woff .woff

AddDefaultCharset utf-8

<IfModule mod_rewrite.c>
   RewriteEngine on
   Options +FollowSymLinks
   RewriteBase /

   RewriteRule   ^favicon.* - [L]

   RewriteRule ^search /categories [R=301,L]
   RewriteRule ^login / [R=301,L]
   RewriteRule ^pages/disclaimer /pages/integritetspolicy [R=301,L]

   RewriteRule ^(.*)/$ http://%{HTTP_HOST}/$1 [R=301,L]

   RewriteRule ^index.php$ http://%{HTTP_HOST} [R=301,L]

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

   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php/$1

   RewriteCond %{HTTPS} off
   RewriteCond %{REQUEST_URI} (utredningar/post)
   RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301]

   RewriteCond %{HTTPS} on
   RewriteCond %{REQUEST_URI} !(utredningar/post)
   RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301]
 </IfModule>

 <IfModule !mod_rewrite.c>
    ErrorDocument 404 /index.php
 </IfModule>

这与域名 (example.com) 和托管服务器完美配合。在 header.view 和其他视图中,链接以

形式给出
<href="/assets/styles/home.css?9">

但是当我尝试在 wamp 的 localhost 中进行这项工作时,它不起作用。资产( css / js / images )未加载且 url 路由不起作用。

这两行我都修改了

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

RewriteCond %{HTTP_HOST} !^localhost
RewriteRule (.*) http://localhost/example/$1 [R=301,L]

我更改了 application/config/config.php ,添加了基本 url ,删除了 index.php 等 ..

我已经尝试了所有可能的方法来使它工作,请指出我在哪里做错了..非常感谢

【问题讨论】:

  • 您使用哪个版本的 CI??
  • 它是 2.1 ,但我也将系统更改为 2.2 .. 仍然无法正常工作..
  • 你在用godaddy服务器吗?
  • 不是它不在godaddy中,在另一个托管服务器中的实时网站,live一个完美运行,但我不能让它成为localhost .. :(
  • 如果您说资产也没有加载,那么您的服务器一定有配置问题。您确定正在读取文件吗?如果将abcdefgh0123 放在文件开头,会引发内部服务器错误吗?

标签: php .htaccess codeigniter routing


【解决方案1】:

这是我的.htaccess,它适用于生产开发服务器。

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

config.php

$config['base_url'] = '';
$config['index_page'] = '';

routes.php

# Default
$route['default_controller'] = "home";

【讨论】:

  • 感谢您的快速回复@Parag,但我之前尝试过.. 它对我不起作用,,
【解决方案2】:

1.在application/config.php文件中进行以下更改

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

2.使用下面的代码在你的根目录中制作.htacces文件

RewriteEngine on
RewriteBase /codeigniter           // add this
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

【讨论】:

  • @UdayaSri 对我的代码 RewriteBase /codeigniter 稍作修改
  • 我试过@stay,但还是不行。我在以前的项目中使用了上面的 htaccess 并且它工作正常..但为此它不起作用。
【解决方案3】:

我尝试了上述所有解决方案,但没有一个对我有用,所以我四处寻找,现在我的本地服务器运行良好

这是你需要做的:正如萨蒂所说

$config['base_url'] = 'http://'.$_SERVER['SERVER_NAME'].'/Your Ci folder_name';
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';

然后添加这个htaccess代码:

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

【讨论】:

    猜你喜欢
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-09-05
    • 2015-10-15
    • 2013-01-01
    相关资源
    最近更新 更多