Forum Moderators: phranque

Message Too Old, No Replies

Images & CSS not showing after RewriteRule

How do I fix it?

         

nbozic

2:00 am on Dec 18, 2003 (gmt 0)

10+ Year Member



I would definitely appreciate help with this problem.

I'm trying to convert this:
[mydomain.com...]
into this:
[mydomain.com...]

My RewriteRule (which works fine):
RewriteEngine on
RewriteRule ^category([0-9]*)/index\.html$ index.php?c=$1 [L]

The .htaccess file is located in the "forum" folder.
The problem is with the images and CSS files which cannot be found.

My images are here:
[mydomain.com...]

From the error log, this is how the server tries to access them:
"File does not exist: /home/myusername/public_html/forum/category1/images/copylogoright.gif"

What should I do? Help!

TGecho

3:41 am on Dec 18, 2003 (gmt 0)

10+ Year Member



The problem is the the browser thinks the page it's viewing is in forum/category1/
The solution is to use absolute paths.

Birdman

3:48 am on Dec 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



TGecho is absolutely correct. I've been down thaqt road too. Remember, you can still use relative URLs, just always give the path from root.

Example:

<img src="/forum/images/file.jpg" />

not

<img src="images/file.jpg" />

Like TGecho said, the user agent thinks it is in the directory that is displayed in the address field, which does not really exist when using mod_rewrite with dynamic URLs.

nbozic

3:48 am on Dec 18, 2003 (gmt 0)

10+ Year Member



OK, thanks. Is it possible to do something with rewrite rules to get around that though?

Birdman

4:49 am on Dec 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I don't think so. You may have to do it manually or use a search and replace program.

jdMorgan

4:51 am on Dec 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



nbozic,

Welcome to WebmasterWorld [webmasterworld.com]!

This should fix the images, but you didn't say where your css is:


RewriteRule ^forum/category1/images/(.*)$ /forum/images/$1 [L]

This is a 'point solution' and only fixes one problem. You may be able to generalize it to include the images and css directories as a variable, but a point solution is the best bet while you figure out how to fix the whole site; It's usually easier to see a more elegant solution after you get everything working.

Jim

Birdman

4:51 am on Dec 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Actually, there may be a way to set the path with HTML. Maybe someone can chime in on that.

nbozic

5:30 am on Dec 18, 2003 (gmt 0)

10+ Year Member



jdMorgan,

It didn't work at first, but after experimenting a little I finally got it. It looks great. This is the final code: RewriteRule ^category1/images/(.*)$ /forum/images/$1 [L]

Thanks.

jdMorgan

5:35 am on Dec 18, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Great!

Now add another rule similar to that one to resolve your CSS files to the proper (sub)directory.

Jim