apache - Clean URL with mod_rewrite including sub directory inside domain -


i trying use mod-rewrite in .htaccess implementing clean/pretty urls.

rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^([^/]+)/?$ details.php?id=$1 [l,qsa] 
  • rewriteengine on turns engine on.

  • rewritecond %{request_filename} !-f not rewrite if request filename exists, , file.

  • rewritecond %{request_filename} !-d not rewrite if request filename exists, , directory.

  • rewriterule ^([^/]+)/?$ details.php?id=$1 [l,qsa] actual rewrite rule. takes after domain name (anything other forward slashes), , rewrites details.php, passing id parameter.

rewriterule ^([^/]+)/?$ details.php?id=$1 [l,qsa] working when request http://www.domain.com/texas

this , good. what need is request url looks this: http://www.domain.com/location/texas

and details.php has below code

<?php $id = $_get["id"]; echo "new id ".$id; ?> 

problem: couldn't write valid .htaccess rewriterule identify request http://www.domain.com/location/texas. please help.

what tried?

rewritecond %{request_filename} !-f

rewritecond %{request_filename} !-d

rewriterule ^location/?$ details.php?id=$1 [l,qsa] - not working

rewriterule ^location/[a-z][-a-z0-9]*?$ details.php?id=$1 [l,qsa] - working, id displayed blank.

you can tweak existing rule making starting location/ optional:

rewriteengine on  rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^(?:location/)?([^/]+)/?$ details.php?id=$1 [nc,l,qsa] 

Comments

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -