I would like to redirect a php page http://example.com/viewer.php?file=anything.jpg to http://example.com/images/anything.jpg How can that be done? Thanks and appreciate if anyone can help.
Two ways - Using ".htaccess" [URL rewriting] or Writing viewer.php. Using the latter way - just write viewer.php.
Thanks! I got it working: if($_GET['file']) header("Location: images/".$_GET['file']); Code (markup):
maybe you want to secure that script a little bit. Filter out these:"/" , "\" and "." to avoid people from redirecting to etc/passwd file.
if (preg_match('~^\w+\.(jpg|gif|png)$~i', $_GET['file'])) header("Location: images/".$_GET['file']); PHP:
You can also do that with htaccess to have SEO Friendly URLS too Add this too you htaccess RewriteEngine On RewriteRule ^images/([^/]*)$ /viewer.php?file=$1 [L] Code (markup):