简体   繁体   English

apache2和CodeIgniter的问题

[英]Issues with apache2 and CodeIgniter

I've seen several questions about apache and CodeIgniter around here but none seems to fit me. 我在这里看到了关于apache和CodeIgniter的几个问题,但似乎没有一个适合我。

What's the problem? 有什么问题?

Apparently apache isn't reading .htaccess file. 显然,apache不读取.htaccess文件。

What have I done to test? 我做了什么测试?

Well, I've created a .htaccess that goes as follows: 好吧,我创建了一个.htaccess文件,其内容如下:

AddHandler  php5-script .php
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|shared|robots\.txt)
RewriteRule ^(.*)$ /index.php?/$1 [L]

In order to test if it was being executed, I've switched for 为了测试它是否正在执行,我已经切换了

RewriteRule .* http://stackoverflow.com/ [L,R] 

Just to check it was executing it. 只是为了检查它是否正在执行。 No such luck. 没有这种运气。

My VirtualHost 我的虚拟主机

<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>

I have tried including .htaccess entries directly on it, but nothing too. 我试过直接在其上包含.htaccess条目,但也没有。

CodeIgniter config.php 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';

I also have changed my hosts file to include 127.0.0.1 videosonline.local which is the url I want to access it. 我还更改了主机文件,使其包含127.0.0.1 videosonline.local,这是我想要访问的URL。

Any guidance will be appreciated! 任何指导将不胜感激!

Edit rewrite module is already enabled and the virtual host mapping is working, but I'm getting 404. 编辑重写模块已启用,并且虚拟主机映射正在运行,但是我收到404。

How I solved this 我如何解决这个问题

Apparently I missed the section 显然我错过了本节

<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride all Require all granted </Directory>

on my apache2.conf. 在我的apache2.conf中。 Make sure you change from AllowOverride none to AllowOverride all . 确保将“ AllowOverride none更改为“ AllowOverride all By doing so, you're telling your apache that .htaccess files inside folders that are within /var/www can overwrite previously defined rules, which is extremely important for CodeIgniter (in case you want to remove index.php from your url). 这样,您就是在告诉您的Apache,/ var / www内的文件夹中的.htaccess文件可以覆盖以前定义的规则,这对于CodeIgniter极为重要(以防您要从URL中删除index.php)。

Hope this helps people in the future. 希望这对以后的人们有所帮助。 Thanks to those who have contributed their time to this question. 感谢那些为解决这个问题做出贡献的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM