1

I am trying to find a better solution to solve the issue. I am not using any framework like silex, Yii, etc. Thus I do not have the general routing handling mechanism provided by these frameworks. My URL patterns are like

routing.php
routing.php?action=create
routing.php?action=list&id=1

and the resulting URL I want to have are

/routing
/routing/create
/routing/list/1

I have some very basic understanding of .htaccess, below is my current foundings

RewriteEngine On
RewriteBase /name/

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

These codes work well to put any .php to /something. However, I am stuck to continue to generate a general solution for getting /routing/create and /routing/list/1 . I appreciate for any helps.

Khawaja Asim
  • 1,327
  • 18
  • 38
onegun
  • 803
  • 1
  • 10
  • 27

1 Answers1

3

Have your .htaccess like this:

RewriteEngine On
RewriteBase /name/

RewriteCond %{DOCUMENT_ROOT}/name/$1.php -f
RewriteRule ^([^/]+)/([^/]+)/?$ $.php1?action=$2 [L,NC,QSA]

RewriteCond %{DOCUMENT_ROOT}/name/$1.php -f    
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1.php?action=$2&id=$3 [L,NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643