Search code examples
mod-rewritexamppdynamic-css

XAMPP Mod_Rewrite & dynamic CSS


I'm running Apache on my local computer (mac) with Mod_Rewite enabled and Allowoveride All set in XAMPP's httpd.conf file.

These are my rules, snippet of httpd.conf file -

RewriteEngine On
RewriteRule ^/setup/css/userlayout.css /setup/css/userlayout.php

Alias /ms "/Users/web/wwwroot/ms"

<Directory "/Users/web/wwwroot/ms">
    Options Indexes MultiViews
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

In my index.php file I have -

<link rel="stylesheet" type="text/css" href="setup/css/userlayout.css?u=1" />

And in my userlayout.php file is -

<?php
    header('Content-type: text/css');
    echo "#test{background-color:#000;}";
?>

Thats everything but the rules don't do anything. I'm not sure if I'm putting the rules in the right place and I understand that you can do this in a httpd.conf file and not the .htaccess file.


Solution

  • I figured out what the problem was. XAMPP setup requires the line "Options +FollowSymLinks" for mod_rewrite to work. Also this has to be placed within the directory tag not outside of it as rewrite rules work per directory which is why i was receiving the error on "RewriteBase /" directive.

    Thus the full code is:

    <IfModule mod_rewrite.c>
        Options +FollowSymLinks 
        RewriteEngine on
        RewriteBase /root
        RewriteRule ^setup/css/userlayout\.css$ setup/css/userlayout\.php
    </IfModule>