I have the following code in my htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#vanity URL
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-_]*)$ /profile.php?username=$1 [L,QSA]
RewriteCond %{THE_REQUEST} \ /profile\.php\?username=([^&\ ]+)&?([^\ ]*)
RewriteRule ^ /%1?%2 [L,R=301]
#remove file extensions
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]
ErrorDocument 400 /404.php
ErrorDocument 401 /404.php
ErrorDocument 403 /404.php
ErrorDocument 404 /404.php
ErrorDocument 500 /404.php
<Files .htaccess>
order allow,deny
deny from all
</Files>
Regarding the vanity URLs, it works fine, but when it comes to remove the php extensions at the end of the URLs, it doesn't work:
1. if i enter mysite.com/home.php
, i do get redirected to home.php
but the extension is still there in the address bar.
2. if i enter mysite.com/home
, i get redirected to my custom error page because home
is not a username is my database.
How can I fix 1. and 2. ?