My website currently has various links to a php script that generates the images dynamically. For example, the link may say "img source="/dynamic_images.php?type=pie-chart&color=red"
Obviously, this is not great for SEO. I'd like to somehow make the filenames of these links appear to be static, and use a solution (like Mod-Rewrite) to ensure that the images can still be dynamically created.
I suppose I could have something like "img src="average-profits-in-scuba-diving-industry.png?type=pie-chart&color=red" (and use Mod-Rewrite to take care of changing the filename prefix to dynamic_images.php), but I'm afraid that the search engines would shy away from the querystring on the end of the image filename.
Any solutions?
Thanks in 开发者_C百科advance.
You'd need something like:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^dynamicChart_([^_]+)_([^_]+).png dynamic_images.php?type=$1&color=$2
Using the above (if I have written it without typos) should mean that requesting dynamicChart_pie-chart_red.png
should translate to dynamic_images.php?type=pie-chart&color=red
I do not think that the SRC attribute for your images are quite as important to SEO as your ALT or TITLE attributes would be.
You normally use mod_rewrite to hide query strings! You can use file names like these in your pages:
/dynamic-images/pie-chart/red/average-profits-in-scuba-diving-industry-19.png
And have mod_rewrite translate them to:
/dynamic-images.php?type=pie-chart&color=red&datasrc=19
For your case use Mod-Rewrite and don't worry about search engines ignoring the query string.
mod_rewrite is one answer, but for something simple like this, it's like nukeing a building to kill a mosquito in one of the rooms. There's $_SERVER['PATH_INFO']
available to extract extra path bits, e.g.
http://example.com/dynamic-images.php/pie-chart/red/average-profits
would have
$_SERVER['PATH_INFO'] = '/pie-chart/red/average-profits';
which you can then parse with:
$query = explode('/', $_SERVER['PATH_INFO']);
and you end up with:
$query = array(
0 => '',
1 => 'pie-chart',
2 => 'red',
3 => 'average-profits';
);
If you don't want the .php extension exposed in the URL, you can force the web server to treat 'dynamic-images' as a PHP script with an AddHandler directive.
精彩评论