[英].htaccess not working - CodeIgniter
我试图在Ubuntu服务器上托管CodeIgniter网站。
所有其他网站工作正常,没有任何问题(服务器包含WordPress和Laravel应用程序)。 但是这个特殊的CodeIngniter网站没有采用.htaccess文件。 我花了一天时间来弄清楚这个问题,但没有运气。
这是细节。
网站网址结构: 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>
CodeIgniter配置文件
$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,该网站正在运行,没有任何问题。 我已经尝试了很多方法但它没有用。
试试这个.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>
添加到.htaccess
RewriteBase /website_name/
在你的RewriteEngine on
之后
我有一种感觉MultiViews
可能会导致一些问题。
在你的VHOST中改变它
Options Indexes FollowSymLinks MultiViews
对此
Options Indexes FollowSymLinks
并且还可能为.htaccess Rewrite添加重写基础
RewriteBase /website_name/
重启apache以进行配置更改
尝试更改你的.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]
不是最终答案,而是测试.htaccess是否在任何级别工作的好方法。
创建此.htaccess并放入根目录
RewriteEngine On
Options +FollowSymLinks
RewriteRule ^test\.html http://www.google.com/? [R=301,L]
然后直接浏览器
http://example.com/test.html
如果你最终在谷歌上,那么你知道.htaccess正在运作。
调试.htaccess的一种有用方法是使用其日志记录功能。 将其添加到您的vhost配置中:
RewriteLog "/tmp/rewrite.log"
RewriteLogLevel 9
您可能需要重新启动apache才能启动日志记录。
最后,我花了整整一天才弄明白这个问题。 这是解决方案。
更新了虚拟主机条目。
<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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.