Ben Ben - 4 months ago 8
MySQL Question

Remove .php from url WITH exceptions (htaccess)

I have the following .htaccess file:

RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ account.php?username=$1

This basically serves my user profiles so like twitter someone can just type:

However I want to make certain pages like /home not lead to a profile but a different .php page, again without the .php at the end.

Can anyone think of a way to do this?



You can have another rule to add .php before this rule:

RewriteEngine On

# To internally redirect file to file.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ $1.php [L]

# handle profile URLs    
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ account.php?username=$1 [L,QSA]