RewriteRule redirecting CSS? [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

RewriteRule redirecting CSS? [SOLVED]

Post 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?
Last edited by Chalks on Thu Dec 11, 2008 2:20 pm, edited 1 time in total.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: RewriteRule redirecting CSS?

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: RewriteRule redirecting CSS?

Post 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.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: RewriteRule redirecting CSS?

Post 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.

:crazy:
Last edited by Chalks on Thu Dec 11, 2008 2:34 pm, edited 2 times in total.
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: RewriteRule redirecting CSS? [SOLVED]

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: RewriteRule redirecting CSS? [SOLVED]

Post by pickle »

Glad to see it's working, though admittedly I'm not sure why it was broken in the first place.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply