.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:

  1. add following line httpd.conf file:

    rewritemap objmap txt://path/to/objectmap.txt 
  2. create text file /path/to/objectmap.txt this:

    articles 0 videos 1 
  3. add 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

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -