Page 1 of 1
RewriteRule redirecting CSS? [SOLVED]
Posted: Thu Dec 11, 2008 2:02 pm
by Chalks
I'm just starting to experiment with the rewrite engine, and my (very) basic .htaccess looks like this:
Code: Select all
RewriteEngine on
RewriteBase /
RewriteRule ^index index.php
RewriteRule /([0-9]+)/$ ?state=$1
In my understanding, that takes the url
mydomain.com/index/8/
and turns it into
mydomain.com/index.php?state=8
And that's how it works. Unfortunately, all of my css immediately disappears. Any ideas why?
Re: RewriteRule redirecting CSS?
Posted: Thu Dec 11, 2008 2:08 pm
by pickle
To be honest, I'm not sure why your CSS is being redirected - maybe an example url would help clarify.
You can put both of those rules into one though:
Code: Select all
RewriteRule ^/index/([0-9]+)/$ index.php?state=$1
Who knows - maybe that'll clear up the problem.
Re: RewriteRule redirecting CSS?
Posted: Thu Dec 11, 2008 2:18 pm
by Chalks
I actually just realized that, pickle, and my htaccess looks like this now:
Code: Select all
RewriteEngine on
RewriteBase /
RewriteRule ^(\w+)/([0-9]+)/$ $1.php?state=$2
which works fine... except for the blasted css.
Here's my index.php header:
Code: Select all
<?php $mustBeLoggedIn = false; $title = "";
require 'include/_head.php'; ?>
<body>
and here's 'include/_head.php'
Code: Select all
<?php
require '_session.php';
include 'codes.php';
if($mustBeLoggedIn && !$loggedIn) {
header("Location: ../notLoggedIn.php");
die();
}
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Secure Prompt <?php echo $title; ?></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="icon" href="images/SP_mark_I.ico" type="image/x-icon" />
<link rel="stylesheet" type="text/css" href="cssjs/sitewide.css" />
</head>
I tried putting rewritecond in like so:
Code: Select all
RewriteEngine on
RewriteBase /
RewriteCond $1 !^.*?\.css$
RewriteRule ^(\w+)/([0-9]+)/$ $1.php?state=$2
but that made no difference.
Re: RewriteRule redirecting CSS?
Posted: Thu Dec 11, 2008 2:19 pm
by Chalks
holy crap, that's retarded. Having a relative filepath for my css was screwing it up. Changing my css path to '/cssjs/sitewide.css' instead of 'cssjs/sitewide.css' fixed it.

Re: RewriteRule redirecting CSS? [SOLVED]
Posted: Thu Dec 11, 2008 2:25 pm
by Chalks
I did try that. What was actually happening was when I went to:
mydomain.com/index/1/
that would be rewritten to
mydomain.com/index.php?state=1
however, my index file was trying to find the css file at
mydomain.com/index/1/cssjs/sitewide.css
which didn't exist.
Re: RewriteRule redirecting CSS? [SOLVED]
Posted: Thu Dec 11, 2008 2:30 pm
by pickle
Glad to see it's working, though admittedly I'm not sure why it was broken in the first place.