1

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
   include( THAT_FILE )
else
   process_URL-->( process-css-files.php )

3 Answers 3

2

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
Sign up to request clarification or add additional context in comments.

Comments

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
}
?>

Comments

0

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]

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.