8th Grader 8th Grader - 10 months ago 26
SQL Question

Detect if php file is being used in <link> or <script> tag

I have a PHP file called

. This fetches CSS code from MySQL and using
Content-type: text/css
. It can be used with

If I use
to rewrite engine, then it would be
. I have a similar file which fetches js (
) code instead.

Instead I want one file called
which can detect which tag it is being used in and fetch the code from the database.


It has been quite a while but I got an answer. Just thought to share it with other people who need something similar to this.

In .htaccess

RewriteEngine On
RewriteBase /

RewriteRule ^file/(.*)\.css$ Home/file.php?id=$1&type=css
RewriteRule ^file/(.*)\.js$ Home/file.php?id=$1&type=js

And In PHP, I would check if the parameter type is equal to css or js and set the content-type header