Home > Software design >  htaccess - the second url param is not visible
htaccess - the second url param is not visible

Time:06-15

example.com/play/music to example.com/play.php?c=music

here is my code which works:

RewriteRule ^play\/music$ play.php?c=music [L]

now I have an extra url param (id as integer) added:

example.com/play/music/54

need to be - example.com/play.php?c=music&id=54

here is my beginning try:

RewriteRule ^play\/music/\d /?$ play.php?c=music&id=$1 [L]  

the page is there but problem is with id param - php doesn't see it

could someone help and explain ?

also, maybe is possible to join both rules (with and without id) in one ?

CodePudding user response:

With your shown samples, please try following .htaccess rules file. Make sure to clear your browser cache before testing your URLs and make sure your .php files(eg: play.php etc) are residing along with .htaccess rules file.

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ $1.php?c=$2&id=$3 [QSA,L]
  • Related