.htaccess - rewrite rule in htaccess didnt work -
im trying beautify urls, urls that
http://www.mysite.com/details.php?id=19&object=1 object=1 (videos) or object=0 (articles)
i want change url to
http://www.mysite.com/videos/19 of course make videos because mentioned when object =1 means videos
and when object =0
i want this
http://www.mysite.com/articles/19 i tried using tutorials , didnt work.nothing happen.
options +followsymlinks rewriteengine on rewriterule ^videos/([a-za-z]+)/([0-9]+)/$ details.php?object=$1&id=$2 and how do if condition rewritecond check if object 1 or 0 , if 1 print videos else articles.
any apreciated.
it better use rewritemap case here. here sample how use it:
add following line
httpd.conffile:rewritemap objmap txt://path/to/objectmap.txtcreate text file
/path/to/objectmap.txtthis:articles 0 videos 1add these line in .htaccess file under
document_root:options +followsymlinks -multiviews rewriteengine on rewriterule ^([^/]+)/([0-9]+)/?$ /details.php?object=${objmap:$1}&id=$2 [l,qsa]
advantage: setup in place, can edit or recreate file /path/to/objectmap.txt anytime have new object id mapping without need add new rules.
update: if have no control on apache config have deal multiple rewrite rules (one each of each object id mapping) this:
options +followsymlinks -multiviews rewriteengine on rewritecond %{the_request} ^[a-z]{3,}\s/+details\.php\?id=([^&]+)&object=1\s [nc] rewriterule ^ /videos/%1? [r=302,l] rewritecond %{the_request} ^[a-z]{3,}\s/+details\.php\?id=([^&]+)&object=0\s [nc] rewriterule ^ /articles/%1? [r=302,l] rewriterule ^videos/([0-9]+)/?$ /details.php?object=1&id=$1 [l,qsa,nc] rewriterule ^articles/([0-9]+)/?$ /details.php?object=0&id=$1 [l,qsa,nc]
Comments
Post a Comment