apache - URL: transform "/news.php?id=1" to "/news/1/" -
i'm trying make more cleaner url's website. have allready found lots of questions regarding removal of file extensions in url's , managed working. want take step further though transforming url http://www.site.com/news.php?id=1 http://www.site.com/news/1/. couldn't find answer specific question i'm asking here. how achieve url's that?
rewrite rules allready have in htaccess:
rewriteengine on rewritecond %{request_filename} !-f rewriterule ^(([a-za-z0-9\-]+/)*[a-za-z0-9\-]+)?$ $1.php
there plenty of questions out there answer question. there 2 things have do:
- redirect ugly url fancy url, user sees fancy url
- internally rewrite fancy url ugly url, server can execute it.
you can find documentation mod_rewrite here. solution uses [end]
flag available apache 2.3.9 , up. can find documentation here. trailing ?
in first rule discards query string.
#redirect ugly url fancy url rewritecond %{query_string} id=([^&]*) rewriterule ^news\.php$ news/%1/? [r] #internally rewrite fancy url usable url rewriterule ^news/([^/]*)/?$ news.php?id=$1 [end]
Comments
Post a Comment