Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

RewriteRule gives me unwanted $_GET param

I need video/5 to be video.php?id=5

RewriteRule ^video$ video.php [L]
RewriteRule ^video/([^/]*)/?$ video.php?id=$1 [QSA,NC,L]

esentially – the above code works – but here is a problem:

video/ – without id – gives me an empty string as $_GET['id']

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

so if I write:

if(isset($_GET['id']))... – the result is true and the value is ""

how to avoid this ?

I want just video/ – without any $_GET variable – except it is set explicitly – for example – video/5

>Solution :

With your shown samples, please try following htaccess rules. Make sure to clear your browser cache before testing your URLs.

RewriteEngine ON
##Internal rewrite to video.php without $1 in it.
RewriteRule ^video/?$ video.php [NC,L]

##Rules for internal rewrite with passing id query string to it.
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^video/([^/]*)/?$ video.php?id=$1 [QSA,NC,L]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading