简体   繁体   中英

Issues with apache2 and CodeIgniter

I've seen several questions about apache and CodeIgniter around here but none seems to fit me.

What's the problem?

Apparently apache isn't reading .htaccess file.

What have I done to test?

Well, I've created a .htaccess that goes as follows:

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.

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.

Any guidance will be appreciated!

Edit rewrite module is already enabled and the virtual host mapping is working, but I'm getting 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. Make sure you change from AllowOverride none to 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).

Hope this helps people in the future. Thanks to those who have contributed their time to this question.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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