Can't get mod_rewrite to work on my Ubuntu 14.04 server

Posted December 26, 2014 44k views

Hi. Can anyone please tell me why my htaccess rewrite is not working? I want to remove the .php extensions and I have the following in my .htaccess file, but to no avail. I am running a LAMP stack on Ubuntu 14.04 x64.

Options -indexes

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteBase /blog

# Allow any files or directories that exist to be displayed directly 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite all other URLs to index.php/URL 
RewriteRule ^(.*)$ index.php/$1 [L] 

<IfModule !mod_rewrite.c> 
ErrorDocument 404 index.php 

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteRule about about.php 

# Apache Rewrite Rules 
<IfModule mod_rewrite.c> 
Options +FollowSymLinks 
RewriteEngine On 
RewriteBase /

# Add trailing slash to url 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/|#(.*))$ 
RewriteRule ^(.*)$ $1/ [R=301,L]

# Remove .php-extension from url 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^\.]+)/$ $1.php

# End of Apache Rewrite Rules 

Can anyone please take a look and tell me what’s wrong with it? Will be much appreciated.


  • Hi! Is mod_rewrite enabled? Try running the following commands:

    sudo a2enmod rewrite
    sudo service apache2 restart
  • Hi @kamaln7 , yes mod_rewrite is enabled. I also tried this guide but it didn’t work.

  • your conf file (located in /etc/apache2/sites-enabled) needs to have this:

        <Directory /var/www/yourwebdirectory>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride all
            Order allow,deny
            allow from all

    then restart apache and see if it is working

  • Hi @sierracircle I already have that included in my 000-default.conf file. I’ve also uncommented a line in apache.conf file as mentioned in a guide to make htaccess work but it’s still not working.

  • Show 22 more comments

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
3 answers

it looks like your link to your stylesheet is the issue. Try changing it to:


instead of


For anyone else looking for an answer here because their rules for permalinks don’t work, remember to disable Multiviews on top of your htaccess file:

<IfModule mod_negotiation.c>
    Options -MultiViews