PDA

View Full Version : CSS does not work after RewriteEngine is added


jwater
09-29-2009, 11:55 PM
In my .htaccess, I have
AddHandler x-mapp-php5 .php .html .htm
Options -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) /error404.php

After I add the last 4 lines, My CSS file does not load. It seems like somehow it got skipped. :confused: How could I fix the problem? Please help!

clunk.werclick
09-30-2009, 07:43 AM
This is *just* a guess because with your code I can't recreate the problem :-(

The only issue I can get at all with your .htaccess here is this line:
AddHandler x-mapp-php5 .php .html .htm seems to toggle something in my config that results in .php files being downloaded rather than parsed. This probably relates to how the main config.

A quick google suggested this :
AddType x-mapp-php5 .php .html .shtml .css
AddHandler x-mapp-php5 .php .html .shtml .css
but I get a 500 error with it:

Curious, I tried to recreate the issue of no .css loading (and no .js for that matter) with a simple file set:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Strict//EN">
<html>
<head>
<title>CSS TEST</title>
<link rel="stylesheet" type="text/css" href="test.css" />
<script type="text/javascript" src="test.js"></script>
</head>
<body onload="JSetup()">
<span class="rednote">TEST 1</span><br>
<span class="whitenote">TEST 2<br>
</body>
</html>


test.css
body{
background-color: #000000;
}
.rednote {
font-family: Verdana, Arial, Helvetica, Geneva, sans-serif;
font-weight: bold;
font-size: 12px;
color: #ff0000;
}
.whitenote {
font-family: Verdana, Arial, Helvetica, Geneva, sans-serif;
font-weight: bold;
font-size: 12px;
color: #ffffff;
}


test.js
function JSetup(){
alert("loaded");
}


I made a number of changes, but I can't get it *not* to load the .css or .js.


I read your rules as;
'If the file exists, serve it - if not show the default index page'
'If the directory exists serve from it - if not show the default index page'
'any other page show error404.php'

Something nags me that the rules are read top to bottom AFAIR, should the directory rule not come before the file rule? I tried switching them on my box, but it makes no difference.

I also changed:
RewriteRule (.*) /error404.php
TO:
RewriteRule ^(.*) /error404.php
Again makes no difference still CNR.

The only thing I wonder is - where is your .css file? (same directory? sub directory? somewhere else?).

In the end I asked myself, is this chap just trying to redirect requests for non existent pages/directories? If so this works for me -
RewriteEngine on
ErrorDocument 404 /error404.php
Does it work for you and fix your issue?