User friendly URL-s with mod_rewrite
I have a PHP project where the page URL-s have the following format:
item.php?productid=7816
about.php?pageid=2Is it possible to bring those URL-s to a more user friendly format like this:
items/item_name [or page title] pages/page_name [or page title]
I know that I can do that with mod_rewrite but have no clues how to do that, how to replace the parameters, etc. with a text.
Any help would be greatly appreciated.
Tha开发者_C百科nks.
In your .htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
then add
RewriteRule PATTERN DESTINATION FLAGS
Where Pattern can be any Regex Pattern to match. In Destination you can use Capture Groups from the Pattern. i.e.
RewriteRule ^[a-z0-9_-]+/([0-9]+)\.html$ show.php?article=$1
Where "$1" is what was matched in the parentheses "([0-9]+)"
then I would rewrite your scripts to accept names instead of ids.
精彩评论