0

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 or mysite.com/page it should display mysite.com/page

2) I should be able to query the stephen data from user.php with this link mysite.com/user/stephen without having previous issue i'm trying to solve

thanks in advance, Stephen.

Sehdev
  • 5,486
  • 3
  • 11
  • 34
Stephynoe
  • 1
  • 1
  • have you tried something like an htaccess simulator: https://htaccess.madewithlove.be – Jan Oct 27 '18 at 11:10
  • Possible duplicate of [Remove .php extension with .htaccess](https://stackoverflow.com/questions/4026021/remove-php-extension-with-htaccess) – Fred Gandt Oct 27 '18 at 13:47

0 Answers0