我在这里看到了关于apache和CodeIgniter的几个问题,但似乎没有一个适合我。
有什么问题?
显然,apache不读取.htaccess文件。
我做了什么测试?
好吧,我创建了一个.htaccess文件,其内容如下:
AddHandler php5-script .php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|shared|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
为了测试它是否正在执行,我已经切换了
RewriteRule .* http://stackoverflow.com/ [L,R]
只是为了检查它是否正在执行。没有这种运气。
我的虚拟主机
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot "/var/www/videosonline"
ServerName videosonline.local
<directory "/var/www/videosonline">
Options Indexes FollowSymLinks
AllowOverride all
Order Deny,Allow
Deny from all
Allow from all
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|shared|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]
</directory>
</VirtualHost>
我试过直接在其上包含.htaccess条目,但也没有。
CodeIgniter config.php
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
| URL to your CodeIgniter root. Typically this will be your base URL,
| WITH a trailing slash:
|
| http://example.com/
|
| If this is not set then CodeIgniter will guess the protocol, domain and
| path to your installation.
|
*/
$config['base_url'] = '';
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
|
| Typically this will be your index.php file, unless you've renamed it to
| something else. If you are using mod_rewrite to remove the page set this
| variable so that it is blank.
|
*/
$config['index_page'] = '';
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
|
| This item determines which server global should be used to retrieve the
| URI string. The default setting of 'AUTO' works for most servers.
| If your links do not seem to work, try one of the other delicious flavors:
|
| 'AUTO' Default - auto detects
| 'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
|
*/
$config['uri_protocol'] = 'AUTO';
我还更改了主机文件,使其包含127.0.0.1 videosonline.local,这是我想要访问的URL。
任何指导将不胜感激!
编辑重写模块已启用,并且虚拟主机映射正在运行,但是我收到404。
我如何解决这个问题
显然我错过了本节
<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride all Require all granted </Directory>
在我的apache2.conf中。确保从更改AllowOverride none
为AllowOverride all
。这样,您就是在告诉您的Apache,/ var / www内的文件夹中的.htaccess文件可以覆盖以前定义的规则,这对于CodeIgniter极为重要(以防您要从URL中删除index.php)。
希望这对以后的人们有所帮助。感谢那些为解决这个问题做出贡献的人。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句