【问题标题】:Codeigniter .htaccess in godaddyGodaddy 中的 Codeigniter .htaccess
【发布时间】:2014-12-21 18:22:42
【问题描述】:

我已经为此苦苦挣扎了好几个小时: 我在 Godaddy 主机的 子文件夹 中有一个 codeigniter 应用程序,可以说:

mydomain.com/myfolder/myapp/

我有这个 .htaccess:

<IfModule mod_rewrite.c>

    RewriteEngine on

    RewriteBase /myfolder/myapp/

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

</IfModule>

我读过这个文档:https://github.com/bcit-ci/CodeIgniter/wiki/Godaddy-Installation-Tips 但这也无济于事。可能是因为我的 ci 应用位于子文件夹中?

如何隐藏 index.php?并使其与友好的网址一起使用?

【问题讨论】:

  • 我只是建议您在当前计划到期时尝试不同的托管,因为 GoDaddy 非常糟糕。来源:亲身经历
  • 很好,但这不是解决方案。我不能对我的客户这么说:P 只是编辑了问题,以防有人可以帮助我

标签: php .htaccess codeigniter mod-rewrite redirect


【解决方案1】:

在您的根目录(codeigniter 的 index.php 所在的位置)中创建一个 .htaccess 文件:

<IfModule mod_rewrite.c>
    RewriteEngine On

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ index.php?/$1 [L]

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    #RewriteCond %{ENV:REDIRECT_STATUS} ^$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]

</IfModule>

然后在您的 application/config/config.php 中:

$config['index_page'] = '';

这应该可以解决问题。

【讨论】:

  • 不,我收到以下错误:未找到在此服务器上未找到请求的 URL /mydomain/index.php。
  • @Perroloco 删除 RewriteBase 行。
  • 这个解决方案对我有用。出现“未指定输入”错误。谢谢!
【解决方案2】:

为 Godaddy 托管服务器使用以下 .htaccess。请让我们知道它是否有效。

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

【讨论】:

    【解决方案3】:

    让你的/myfolder/myapp/.htaccess 像这样:

    <IfModule mod_rewrite.c>
    
        RewriteEngine on
    
        RewriteBase /myfolder/myapp/
    
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php/$1 [L]
    
    </IfModule>
    

    那么在/myfolder/myapp/application/config/config.php你需要有这个配置:

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

    【讨论】:

    • 谢谢!现在它不会给我一个错误,但它总是打开欢迎控制器,即使我尝试去另一个!你知道发生了什么吗?
    • 没关系!我将 uri 协议更改为 auto,现在它可以工作了!谢谢
    【解决方案4】:

    我很惊讶没有人写你应该放

    Options +FollowSymlinks
    

    在 .htaccess 文件的开头,用于 GoDaddy 托管网站。

    【讨论】:

      猜你喜欢
      • 2013-03-23
      • 1970-01-01
      • 2015-08-11
      • 2013-06-14
      • 1970-01-01
      • 2015-12-03
      • 2020-07-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多