简体   繁体   中英

convert clean url to normal url by mod_rewrite php

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?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM