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.

1 Answer 1

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]
Sign up to request clarification or add additional context in comments.

1 Comment

hi, is it possible to replace "routing" words with a regex which can take in any name?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.