dodea4
By:
dodea4

Remove URL extension with a2enmod rewrite with htaccess

November 7, 2015 1.5k views
Apache PHP

Hi there :-)

I am trying to enable the URL rewrite so that when a person goes to http://sitename.org/home.php they will not see the extension or .php .

I cannot get it to work unfortunately, this is what i have done:

I think I must be missing something small here:

my htaccess:


RewriteEngine On
RewriteCond %{REQUESTFILENAME} !-d
RewriteCond %{REQUEST
FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]


set permissions to 664

a2enmod is enabled

removed extension from links in code (changed link in nav menu form /home.php to /home)

restarted apache

when i got to .../home - i get a 404.

1 Answer

Make sure that you have AllowOverride set to All in your apache virtual host file.

<Directory /var/www/html>
        Options -Indexes +FollowSymLinks +MultiViews
        AllowOverride All
        Require all granted
</Directory>

And then restart apache.

Have another answer? Share your knowledge.