For example:
HANDLER *.css --> process-css-files.php
HANDLER *.(jpg|png|gif|jpeg) --> process-image-files.php
In addition how to:
if (*.css EXISTS) then
in开发者_Python百科clude( THAT_FILE )
else
process_URL-->( process-css-files.php )
I use something like this for combining css scripts within the css folder to a single concatenated file:
RewriteRule ^css/(.*\.css) /combine.php?file=$1
For the most part, you're going to use mod_rewrite to redirect URLs. You should put the following in your .htaccess file (if your server has support for it):
RewriteEngine on
RewriteRule ^/?(.+)\.css$ process-css-files.php?name=$1
RewriteRule ^/?(.+)\.(jpg|jpeg|gif|png)$ process-image-files.php?name=$1&extension=$2
That would solve the first part of your question (I think). I'm sure there's a way to get .htaccess to check if a file exists before rewriting the URL, but I'm more experienced with PHP, so I'd probably just always redirect to the PHP file, and then have PHP do all the checking and whatnot:
<?php
$name = $_GET['name'].'.css';
header('Content-type: text/css');
if (file_exists($name)) {
echo file_get_contents($name);
} else {
// do whatever
}
?>
I believe all this can be handled by .htaccess rules. Try something this:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^([^.]*\.(jpe?g|png|gif))$ process-image-files.php?img=$1 [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]*\.css)$ process-css-files.php?css=$1 [L,NC]
精彩评论