views:

127

answers:

3

Hi there! I'm using mod_rewrite to clean up some of my URL's (duh) and I got it working. Sorta. It redirects to the correct page, but the stylesheet doesn't show up. Here's my code in .htaccess:

RewriteEngine on
RewriteRule ^blog/([^/\.]+)/?$ post.php?page=$1 [L]

So what's going on? This is my first time working with mod_rewrite, by the way.

+1  A: 

Your CSS (Lets Assume /blog/style.css) is going to post.php?page=style.css

To Fix, I'd suggest putting this right after the RewriteEngine

RewriteCond %{SCRIPT_FILENAME} -f
RewriteCond %{SCRIPT_FILENAME} -d

That will forward all requests where the file exists, like a CSS/JS file, directly to the file.

In the future, I suggest browsing to the URL on a browser, and see where it leads you to. If it doesn't work in the browser, it won't work for the page.

Chacha102
Ok, right now the stylesheet is inits own directory at /style/stylesheet.css Does that change anything? I did what you said above and it gave me a 404 error. Also, I don't see why it doesn't work because when I go to the URL that its REALLY going to, it works perfectly. Isn't it basically just doing a redirect, and there fore just like going to the ACTUAL page? Confused...
WillyG
If you browse to some.thing.com/style/stylesheet.css, do you get it? If so, your HTML page should have the same URL you browse to to get it as the CSS page in your <link> tag.
Chacha102
+1  A: 

It’s probably just your new URLs that cause that relative URLs are resolved differently than with your old URLs. Try it with an absolute URL path like this:

/style/screen.css

Instead of a relative URL path like:

style/screen.css
./style/screen.css
Gumbo
Thanks so much!!
WillyG
+1  A: 

It could be your CSS link is broken by your new URLs if you are using relative links. e.g:

Stylesheet link used: ../css/stylesheet.css
Old page: /blog/example/post.php
New page: /blog/2009/12/example/post.php

This break would affect images too. An easy way to fix this is to decide upon the definitive URL for the CSS and absolute link it. e.g.

/css/stylesheet.css

This would mean that irregardless of where you are in the structure, the CSS (or images, if you follow this routine) would show up ok.

Amadiere
Thanks so much!!
WillyG