Welcome to WebmasterWorld Guest from 34.239.158.107

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

Images & CSS not showing after RewriteRule

How do I fix it?

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


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!

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

Preferred Member

10+ Year Member

joined:May 24, 2003
posts:381
votes: 0


The problem is the the browser thinks the page it's viewing is in forum/category1/
The solution is to use absolute paths.
3:48 am on Dec 18, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


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.

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

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


OK, thanks. Is it possible to do something with rewrite rules to get around that though?
4:49 am on Dec 18, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


I don't think so. You may have to do it manually or use a search and replace program.
4:51 am on Dec 18, 2003 (gmt 0)

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


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

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

Senior Member

WebmasterWorld Senior Member 10+ Year Member

joined:Apr 22, 2002
posts:2546
votes: 0


Actually, there may be a way to set the path with HTML. Maybe someone can chime in on that.
5:30 am on Dec 18, 2003 (gmt 0)

Junior Member

10+ Year Member

joined:Dec 18, 2003
posts:57
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member

joined:Mar 31, 2002
posts:25430
votes: 0


Great!

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

Jim

 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members