tags:

views:

120

answers:

2

Hai

I have worked with clean URL in php. Now I want to convert a clean URL to normal php URL Like http://localhost/url/user/2/a to http://localhost/url/user.php?id=2&sort=a

Can any one give me the way to do this?

also i have one more question. Is there is any way to do this with out .htaccess?

+1  A: 

In your .htaccess file in your root directory:

RewriteEngine On
RewriteRule ^url/user/(\d+)/([a-zA-Z]?)$ /url/user.php?id=$1&sort=$2

should do it.

richsage
k. thanks. I have one more doubt. Is there is any way to do this with out .htaccess?
Testadmin
Not unless you organise your scripts into relevant directories, or provide a front controller like Col.Shrapnel suggests (but precede every URL with `?` so it redirects to your index.php file).
richsage
A: 

I'd suggest not to write specific rule for the every module, but make a front controller which will receive all requests and the dispatch them to the corresponding modules.

RewriteEngine on
RewriteBase /
RewriteCond  %{REQUEST_FILENAME} !-f
RewriteCond  %{REQUEST_FILENAME} !-d
RewriteRule  ^(.*)$ index.php?uri=$1 [QSA,L]

So, you'll end up with $_GET['uri'] parameter in your script, which can be parsed to get required values

Col. Shrapnel
thanks. One more question. Is there is any way to do this with out .htaccess?
Testadmin
@Testadmin no way. Just because it is not PHP but a web-server, who receive and serve an client's request. PHP has nothing to do with it. So, the only web-server configuration can be used.
Col. Shrapnel