Php Image Url From /buildimg.php?1=2816 To /picture_2816.png?
Solution 1:
What you're asking is done at the webserver level, before the request reaches PHP. You need to configure your webserver to send all requests for the desired URL format to the PHP script.
You don't state what webserver you're using. The following answer applies if you're using Apache, which is arguably the most common webserver for powering PHP sites.
One way to do this is using the Apache mod_rewrite module. mod_rewrite
allows Apache to "rewrite" specific URLs to transform them into other URLs.
The specific Apache directive you want are:
RewriteEngine on
RewriteRule ^/noobtest/picture_([0-9]+)\.png$ /noobtest/buildimg.php?id=$1 [L]
These should be placed into your Apache's <VirtualHost>
configuration directive in httpd.conf
or similar. If you don't have access to the server's configuration, you can try placing these in a .htaccess
file. .htaccess
files are per-directory configuration files (names, you guessed it, .htaccess
) which contain Apache directives. Using a .htaccess
file is less efficient but may be required.
To set up a RewiteRule using a .htaccess
file, create a file /noobtest/.htaccess
containing:
RewriteEngine on
RewriteRule ^picture_([0-9]+)\.png$ buildimg.php?id=$1 [L]
Note that you don't specify the directory here. Also, note that mod_rewrite must be loaded by your server already and you must have permission (via AllowOverride
) to override Apache's configuration in this way. If either of those is not true and you can't modify Apache's configuration files, you're out of luck.
Post a Comment for "Php Image Url From /buildimg.php?1=2816 To /picture_2816.png?"