1

Another url rewrite question, apologies, but having a bit of trouble.

I have removed the .php extension from my files:

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php

note: [app/ is set as the public directory]

note: [Apache server]

Goal

What I would like is to have URLs like such:

www.example.com/app/user/123 instead of www.example.com/app/user.php?id=123

I tried: RewriteRule ^user/([0-9]+)/?$ user.php?id=$1 [R=301,L,NC] but it just returns an 500 Internal Server Error

  • Also will this affect GET and POST requests, or will the php need to be coded to reflect the url change?

Links I came across

right order of rewrite rules in an htaccess file

http://corz.org/serv/tricks/htaccess2.php

http://www.workingwith.me.uk/articles/scripting/mod_rewrite

.htaccess RewriteRule to preserve GET URL parameters

plus many others.

EDIT

Does the first rule of removing the.php affect the rules that come after it? i.e. stop them from processing

Community
  • 1
  • 1
ashley
  • 2,749
  • 5
  • 26
  • 38

1 Answers1

1

Ordering of rules is probably causing this problem. Try these rules in proper order:

RewriteEngine On
RewriteBase /app/

RewriteRule ^user/([0-9]+)/?$ user.php?id=$1 [QSA,L,NC] 

# hide .php extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/app/$1.php -f
RewriteRule ^(.+?)/?$ /$1.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643