Reputation: 2035
I'm trying to make it possible to hide the PHP extension on my website so for example, if I go to http://code-up.nl/contact, the http://code-up.nl/contact.php file will be loaded instead. I have several domains on my server. In the root of the website (located at /var/www/code-up.nl) I have the following .htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [L]
And in my apache virtual hosts file, I've put AllowOverride to All:
<VirtualHost *:80>
ServerAdmin webmaster@localhost
ServerName code-up.nl
ServerAlias www.code-up.nl
DocumentRoot /var/www/code-up.nl
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/code-up.nl/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
I think everything is right but I still get an error 404 when I go to http://code-up.nl/contact. I've searched for a solution and tried many things but it just won't work. Can anyone help with this?
Upvotes: 0
Views: 1188
Reputation: 9279
Try this in your .htaccess under DOCUMENT_ROOT:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
Upvotes: 3