Help about htaccess and php
I am building a php site(raw coding). I want to modify the url. i think htaccess is the solution. but i am weak is this. can u people help me about this? my urls are like these:
- www.site.com/index.php
- www.site.com/invoice_details.php?invoice_id=100
- www.site.com/user.php?uid=20&type=1
- www.site.com/client_details.php?cid=10&status=act开发者_如何学Pythonive
I want these to be like:(1st choice)
- www.site.com
- www.site.com/invoice-details/100
- www.site.com/user/20/1
- www.site.com/client-details/10/active
Or may be just add "slash" and replace the "_" with "-"(2nd choice)
You can solve that using mod_rewrite, which can be configured in .htaccess files.
For example, to solve your number 1 and 2:
RewriteEngine on
RewriteRule ^invoice-details/([^/\d]+)?$ invoice_details.php?invoice_id=$1 [L]
RewriteRule ^user/([^/\d]+)/([^/\d]+)$ user.php?uid=$1&type=$2 [L]
There's masses of information online, this http://www.workingwith.me.uk/articles/scripting/mod_rewrite seems like a reasonable introduction.
You're problem cannot be solved with just .htaccess though that is needed.
What want to do is called URL Routing and requires some code to handle the request properly.
Here's a decent tutorial: http://www.phpaddiction.com/tags/axial/url-routing-with-php-part-one/
精彩评论