【问题标题】:.htaccess not working on server.htaccess 在服务器上不起作用
【发布时间】:2017-05-17 08:32:03
【问题描述】:

我已将网站托管为"http://www.sitename.com/projectfoldername/" 之类的子文件夹。 这里它只显示主页,当点击任何菜单时它显示 404 错误,所以我通过在控制器名称之前写入 index.php 来更改 url,现在 url 已经从这个更改: "http://www.sitename.com/projectfoldername/controller-name/function-name" 到此:"http://www.sitename.com/projectfoldername/index.php/controller-name/function-name" 然后它显示页面但仅在本地工作..

我的 htaccess 文件

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

config.php

$config['base_url'] = 'http://www.sitename.com/projectfoldername/';
$config['index_page'] = '';
$config['uri_protocol'] = 'REQUEST_URI';

【问题讨论】:

    标签: .htaccess codeigniter hosting


    【解决方案1】:

    如果您使用 Apache Web 服务器,请激活您的 mod_rewrite

    在 Ubuntu 上:

    sudo a2enmod rewrite
    

    在窗口上:

    打开你的 httpd.conf 并找到该行

    #LoadModule rewrite_module modules/mod_rewrite.so and remove the hash ‘#’
    

    【讨论】:

    • 在服务器哪里可以找到这个文件?
    【解决方案2】:

    @antroo ghosh ,首先你必须知道使用的是哪个 Web 服务器(Apache 或 IIS)。

    如果您使用的是 windows(IIS) 服务器,则不能使用 .htaccess,在 IIS 中您必须使用 web.config 而不是 .htaccess。

    更多详情https://www.iis.net/learn/application-frameworks/install-and-configure-php-applications-on-iis/translate-htaccess-content-to-iis-webconfig

    希望对你有帮助!

    【讨论】:

      【解决方案3】:

      尝试在 .htaccess 中添加以下内容,它可能会对您有所帮助。

      RewriteEngine on
      RewriteCond %{REQUEST_FILENAME} -s [OR]
      RewriteCond %{REQUEST_FILENAME} -l [OR]
      RewriteCond %{REQUEST_FILENAME} -d
      RewriteRule ^.*$ - [NC,L]
      RewriteRule ^.*$ index.php [NC,L]
      

      【讨论】:

        【解决方案4】:

        在您的.htaccess 文件中使用RewriteBase /projectfoldername,如下所示:

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

        【讨论】:

          猜你喜欢
          • 2015-07-04
          • 2013-01-30
          • 2010-11-10
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2011-06-10
          • 1970-01-01
          相关资源
          最近更新 更多