Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Apache 2.4.6 default.conf format changed. Unable to run .htaccess

Guys. I am using codeigniter. I used .htaccess to remove 'index.php' from my url's, and added "Allow from all" to my default.conf. 'index.php' was removed successfully and the site was running. But since the last update of apache, .htacess stopped working and 'index.php' became necessary in the url's. This is my new updated 000-default.conf.

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
#vim: syntax=apache ts=4 sw=4 sts=4 sr noet

I added the following lines to my 000-default.conf, but didn't work:

AllowOverride all
Order allow,deny
Allow from all

My .htaccess is alright because it was working fine before the last update of Apache.

Options -Indexes
RewriteEngine on

RewriteBase /
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

RewriteCond %{REQUEST_URI} ^htaccess/ [NC,OR]
RewriteCond %{REQUEST_URI} ^system/function/ [NC,OR]
#just make sure the last rule does  NOT have an OR
RewriteCond %{REQUEST_URI} ^system/class/ [NC]
RewriteRule . - [R=404,L,NC]

My apache version is 2.4.6. Now please tell me what to add to the 000-default.conf to get the .htaccess working and remove 'index.php' from my site url's.

P.S: I am using ubuntu 12.04. mod_rewrite is enabled. I have enabled 000-default.conf i.e. it is available in my sites-enabled folder.

like image 465
CodeAddict Avatar asked Nov 11 '13 20:11

CodeAddict


People also ask

Why is my .htaccess file not working?

Improper syntax being used It is quite common for a syntax error to be the reason for an . htaccess file not working. If you are familiar with how to read and configure . htaccess rules, double check your configuration.

Where is .htaccess file in Apache?

htaccess file can be found at /opt/bitnami/APPNAME/. htaccess. Some applications do not have the /opt/bitnami/apache2/conf/vhosts/htaccess/APPNAME-htaccess.

What is htaccess in Apache?

htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.


3 Answers

I'm still a new to server/command line land, so I thought I'd append a step by step solution for others in a similar place. Hope this helps someone out:

  1. Login to your server.

  2. Open the 000-default.config file with nano:

    $ sudo nano /etc/apache2/sites-available/000-default.conf
    
  3. Look for this line within VirtualHost: DocumentRoot /var/www/html and add the following just underneath it:

    <Directory /var/www >
        AllowOverride All
    </Directory> 
    
  4. Save your edits: Press CTRL + O to Writeout; then hit RETURN to save your changes

  5. Exit Nano: Press CTRL + X

  6. Restart your server:

    $ sudo service apache2 restart
    
  7. If you need to activate the apache mod_rewrite module, run this command:

    $ sudo a2enmod rewrite 
    

    And if the module is already activated, you'll get a message letting you know all is well.

like image 169
KittenLogic Avatar answered Sep 27 '22 21:09

KittenLogic


This is a bit old, but since I'm seeing it now and I got it to work, maybe this will clarify for anyone stumbling on it.

You open up that 000-default.conf file and find where it says "/var/www" then put this in:

<Directory /var/www>
AllowOverride All
</Directory>

Then just save and restart apache. You also need to have mod_rewrite turned on for Apache. That's easy to find by Googling.

like image 29
user3077947 Avatar answered Sep 27 '22 21:09

user3077947


ServerName localhost

ServerAdmin webmaster@localhost
DocumentRoot /var/www
     <Directory /var/www >
            AllowOverride All
    </Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined

;)

like image 25
Pablo Merino Avatar answered Sep 27 '22 19:09

Pablo Merino