.htaccess在服务器上无法正常工作

问题描述:

我承载了一个网站作为"http://www.sitename.com/projectfoldername/"这样的子文件夹。 在这里它只显示主页,当点击任何菜单时,它显示404错误,所以我通过编写index.php之前控制器名称现在URL已更改从这里: "http://www.sitename.com/projectfoldername/controller-name/function-name"到这个:"http://www.sitename.com/projectfoldername/index.php/controller-name/function-name"然后它显示了网页,但只能在本地工作...htaccess在服务器上无法正常工作

我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'; 

如果使用Apache Web服务器,活跃你的mod_rewrite

在Ubuntu:

sudo a2enmod rewrite 

在Window:

打开你的httpd.conf并找到行

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

使用RewriteBase /projectfoldername.htaccess文件像这样:在.htaccess

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

不工作,不改变 –

尝试添加以下的,它可以帮助你。

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

不工作,不改变 –

@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

我但愿这可以帮助你!