: Rewrite URL to a PHP script with parameters I'm trying to create a service that you give it a URL like http://myhost.com/34.png and it will return the result of the script http://myhost.com/create_image.php?count=34.
I'm trying to create a service that you give it a URL like myhost.com/34.png and it will return the result of the script myhost.com/create_image.php?count=34.
I know this is possible with mod_rewrite, but I'm very new to this and I'd like some pointers on how to do this. I only want it to work for numbers.
More posts by @Sue5673885
1 Comments
Sorted by latest first Latest Oldest Best
ServerFault's Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask topic is a great start - but, more to the point, you're looking for something like this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} ^/([0-9]*).png$
RewriteRule ([0-9]*).png$ /create_image.php?count= [L]
Line 1: Enable the mod_rewrite engine (the mod_rewrite Apache module may need to be installed and enabled separately of this directive if it is not already active - i.e. if "RewriteEngine on" throws an error)
Line 2: If (and only if) the request file path begins with a leading slash and is composed of a numeric string (of arbitrary length) followed by the ".png" extension (note use of character for escaping) then...
Line 3: Set the variable to the numeric string and pass the request on to the create_image.php file with the count parameter set accordingly then stop (L = last request)
I highly recommend the AskApache mod_rewrite tutorials if you're just picking up mod_rewrite - I believe you'll find it's pretty easy to get the hang of it if you're accustomed to writing scripts.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.