.htaccess rewrite rules doesn't work

October 27, 2014 7k views

I've tried to follow this guide to enable the .htaccess on my server (so my .htaccess is working), but without luck.

Does anyone know where the problem can be?

Here is my htaccess file, it works on my localhost etc.

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
  • what are you trying to achieve with your .htaccess configuration ?

  • URLs that are beautiful.

    For instance "index.php/hello/world" would become "hello/world" - so the index.php is removed.

    This is working without problems on my localhost as mentioned, so I think it's some kind of server setup that is giving problems

3 Answers

To remove the .php using .htaccess file, your .htaccess doc should look like this:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

In case you want to remove a .html extension and not a .php replace the last line with this:

RewriteRule ^([^\.]+)$ $1.html [NC,L]

Finally for beginners, you can create .htaccess files from htaccesseditor.com
Using their web interface

Hope this helps ;)


  • That's not the problem. The problem is that the server doesn't allow my htaccess file. The file itselfs is at it should be.

  • Okay how do you mean doesn't allow ?
    Can you write to the .htacces file successfully ?
    Are you doing this using a user with the appropriate permissions level ?

  • I just get "Not found" error, like the htaccess isn't installed or I'm missing to configurate something on the server.
    Any idea what that could be?

  • Edit your VirtualHost config in /etc/apache2/sites-enabled and set AllowOverride to All. Then, restart Apache:

    sudo service apache2 restart
  • Awesome, it worked - thanks!

It does not work for me even if set AllowOverride All.
What else can be a problem?

Have another answer? Share your knowledge.