【问题标题】:.htaccess file does not working on godaddy server.htaccess 文件在 godaddy 服务器上不起作用
【发布时间】:2016-12-12 04:00:55
【问题描述】:

谁能告诉我为什么这段代码可以在我的本地服务器上运行,但不能在 Godaddy 服务器上运行?

我在 Godaddy 上收到以下错误...

我创建了一个 codeigniter 项目并在 godaddy 服务器上托管,但 .htaccess 文件不起作用

我的问题是“https://www.tripbrip.com/index.php/home/app_view”这个相同的 url 出现在我的 url 端,但我想删除这个链接中的 index.php

我的目录结构是这样的:

Options +MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ index.php/?$1 [NC,L]

my config file:
$config['base_url'] = "https://".$_SERVER['HTTP_HOST'].'/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

此文件在我的本地主机中运行,但在服务器上不起作用。

我使用了很多代码,但问题仍然存在。

如果我浏览到 http://example.com/bootstrap.php,我会得到一个 404 资源在 / 处不可用

【问题讨论】:

标签: php .htaccess codeigniter


【解决方案1】:

也许你可以尝试把它放在你的 .htaccess 中

<IfModule mod_rewrite.c>
#RewriteEngine on
#RewriteBase    /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule .* index.php/$1 [PT,L]

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

</IfModule>

对于您的配置文件。也许你可以清空它。

$config['base_url'] = '';

如果还是报错,可以试试这个

$config['base_url']  =  "http://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= preg_replace('@/+$@', '', dirname($_SERVER['SCRIPT_NAME'])).'/';

【讨论】:

    【解决方案2】:

    以下设置对我来说很好。

    RewriteEngine on -MultiViews
    Options All -Indexes
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    #RewriteRule ^(.*)$ index.php/$1 [L]
    RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
    

    application =&gt; config =&gt; config.php

    $config['index_page'] = ''; // should be blank
    

    而不是

    $config['index_page'] = 'index.php';
    

    【讨论】:

    • 非常感谢您的回答。我根据您的建议使用了此代码,但问题仍然存在。所以任何其他方法来解决这个问题请建议我
    • @ShivrajHipparge 我再次更新了我的答案。希望它能解决问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-10
    • 2019-08-04
    • 1970-01-01
    • 2017-05-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多