2015-11-27 176 views
3

我试过在Ubuntu服务器上托管一个CodeIgniter网站。.htaccess无法正常工作 - CodeIgniter

所有其他网站工作正常,没有任何问题(服务器包含WordPress和Laravel应用程序)。但是这个特殊的CodeIngniter网站并没有采用.htaccess文件。我花了一天的时间来解决这个问题,但没有运气。

这是细节。

网站URL结构:http://example.com/website_name

.htaccess文件

<IfModule mod_rewrite.c> 
    RewriteEngine on 
    RewriteCond $1 !^(index\.php|resources|robots\.txt) 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)$ index.php/$1 [L] 
</IfModule> 

虚拟主机条目

<VirtualHost *:80> 
    ServerName example.com 
    ServerAlias example.com 
    DocumentRoot "/var/www/example.com" 
    <Directory "/var/wwww/example.com"> 
      Options Indexes FollowSymLinks MultiViews 
      AllowOverride ALL 
      Order allow,deny 
      allow from all 
    </Directory> 
</VirtualHost> 

笨配置文件

$config['base_url'] = 'http://example.com/website_name/'; 
$config['index_page'] = ''; 
$config['uri_protocol'] = 'REQUEST_URI'; 

,当我试图访问该网站的输出如下,

Not Found 
The requested URL /website_name/test was not found on this server. 

但是如果我添加的index.php,在该网站的工作没有任何问题。我尝试了很多方法,但没有奏效。

回答

0

最后,我花了整整一天的时间就想出了这个问题。这是解决方案。

已更新的虚拟主机条目。

<VirtualHost *:80> 
    ServerName example.com 
    DocumentRoot /var/www/example.com/ 

    # Additional section added to get the htaccess working in sub folder. 
    Alias /website_name/ /var/www/example.com/website_name/ 
    <Directory /var/www/example.com/website_name/> 
     Options Indexes FollowSymLinks MultiViews 
     AllowOverride all 
     Order allow,deny 
     allow from all 
    </Directory> 
</VirtualHost> 
1

试试这个的.htaccess

<IfModule mod_rewrite.c> 
    Options +FollowSymLinks 
    Options -Indexes 
    RewriteEngine On 
    RewriteBase /website_name/ 

    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteCond %{REQUEST_FILENAME} !-d 

    RewriteCond $1 !^(index\.php) 
    RewriteRule ^(.*)$ index.php [L] 

</IfModule> 
+0

试过这个,没有工作。 – Nikhil

+0

RewriteBase/website_name/ – AldoZumaran

+0

将htaccess文件放到website_name文件夹中 – AldoZumaran

1

添加到您的.htaccess

RewriteBase /website_name/

RewriteEngine on

+0

我已经试过这个,它不起作用。 – Nikhil

+0

你可以检查你的apache的error_log和access_log这个域吗? – sotoz

+0

tail -f /var/log/apache2/error.log不会返回与本网站相关的任何内容。 – Nikhil

0

后试着改变你的.htaccess这样。

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

或者这

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

不是最终的答案,但以测试的.htaccess在任何一级工作的好办法。

创建此的.htaccess,放在根目录如果你最终在谷歌,那么你知道的.htaccess工作

RewriteEngine On 
Options +FollowSymLinks 
RewriteRule ^test\.html http://www.google.com/? [R=301,L] 

然后直接在浏览器中

http://example.com/test.html 

一个有用的调试.htaccess的方法是使用它的日志记录功能。 添加到您的虚拟主机的配置:

RewriteLog "/tmp/rewrite.log" 
RewriteLogLevel 9 

你可能需要重新启动Apache获得记录开始。

1

我有一种感觉MultiViews可能会导致一些问题。

变化这在VHOST

Options Indexes FollowSymLinks MultiViews 

这个

Options Indexes FollowSymLinks 

而且还可能增加rewritebase为.htaccess重写

RewriteBase /website_name/ 

重新启动Apache的配置改变