I need to generate clean url for my website, and after a week of searching i was able to arrive at this.
RewriteEngine On
RewriteBase /
# remove .php extention from web pages
RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ /$1.php [NC,END]
the rewrite rule is working perfectly e.g "mysite.com/user.php" result in "mysite.com/user" "mysite.com/user/profile.php" result in "mysite.com/user/profile"
Now, the issue I'm having is this; when i add query rule like the following
# remove .php extention from web pages and query
RewriteRule ^(.+)\.php$ /$1 [R,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/(.*?)/?$ /$1.php?user=$2 [NC,END]
the query works for link like this; mysite.com/user/stephen
but when i try to visit mysite.com/user
again it send me to the 404 page
now these are my aims:
1) If someone visit
mysite.com/page.php
ormysite.com/page
it should displaymysite.com/page
2) I should be able to query the stephen data from
user.php
with this linkmysite.com/user/stephen
without having previous issue i'm trying to solve
thanks in advance, Stephen.