Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 19th, 2005, 6:57 PM   #1
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
Apache mod_rewrite

I am on the quest to make my URL's more user friendly.
I have decided to use the oh-so-common method of:
/somevarhere/anothervarhere/etc/
instead of
index.php?a=somevarhere&b=anothervarhere&c=etc

The problem is that the file paths inside the HTML page (to images and css files) detects the relative path as from the mod_rewritten URL as opposed to the actual directory.

So if I have this image path in a file:
images/bg.gif

It would turn out to be:
/somevarhere/anothervarhere/etc/images/bg.gif

I'm not really sure how to fix this, but any help is much appreciated.
Eryk is offline   Reply With Quote
Old Sep 19th, 2005, 7:10 PM   #2
tempest
Programming Guru
 
tempest's Avatar
 
Join Date: Oct 2004
Posts: 1,041
Rep Power: 5 tempest is on a distinguished road
Send a message via ICQ to tempest Send a message via AIM to tempest Send a message via Yahoo to tempest
Not sure what you're saying, but try "/image/bg.gif". This sounds more like an HTML issue.
__________________

tempest is offline   Reply With Quote
Old Sep 19th, 2005, 7:10 PM   #3
OpenLoop
Expert Programmer
 
OpenLoop's Avatar
 
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4 OpenLoop is on a distinguished road
I'm really confused here. So you have a problem with paths, do you have a single page(small one) that you can post the code for and the path on the server so we can see the problem in action. Also why don't you create symbolic links to the files in the new path or just move them there?
OpenLoop is offline   Reply With Quote
Old Sep 19th, 2005, 7:51 PM   #4
Dameon
Troll
 
Dameon's Avatar
 
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4 Dameon is on a distinguished road
mod_rewrite allows more "friendly" urls as he said. On the server side, the path requested by the browser is converted to a querystring. The browser has no part of this mod_rewrite magic. If you use relative URLs in the HTML, the browser as he said would append that to a nonexistant directory. There is no http://example.com/shop.php/buy/item57, for example, but because of mod_rewrite, Apache treats it like shop.php?action=buy&item=item57 (Or similar, never actually used mod rewrite).

From installing various forums and CMS systems, it seems common practice to have an include file included by all source files that defines variables for things such as database info and the website address. Do that, and when sending out the page a link is no longer to /folder/example.html but to <address variable> + /folder/example.html The browser then knows that it is looking for http://example.com/folder/example.html (Base directory + path to item) and not http://example.com/shop.php/buy/item...r/example.html (What the browser thinks is the current directory + path to item)

In summation, mod_rewrite just creates a stronger need for absolute linking. So why not just stick with querystrings?
__________________
MD5(sig) = bcef75433db02e9ad9bf81d6f7c5c270
Dameon is offline   Reply With Quote
Old Sep 19th, 2005, 8:14 PM   #5
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
An aside: don't use it if you don't have control of the server. My host doesn't implement it, although I do on my local machine.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Old Sep 21st, 2005, 5:50 PM   #6
Eryk
Programmer
 
Join Date: Jul 2005
Posts: 62
Rep Power: 4 Eryk is on a distinguished road
@Dameon:
So your suggestion is just to use absolute linking?

@DaWei:
I happen to know that my host implements it, but do you think I should still not use it?

@tempest & OpenLoop:
mod_rewrite is an apache command that allows you to allow users to use a URL that doesn't exist to access a page that does. Like it may seem as though there are hundreds of sub-directories, but almost none (or none) of them exist.

It's not just an HTML problem, because without using the mod_rewrite and by accessing the page directly I get all the file paths to turn out ok. The "new path" doesn't exist and is just like an illusion.
Eryk is offline   Reply With Quote
Old Sep 21st, 2005, 6:02 PM   #7
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Quote:
I happen to know that my host implements it, but do you think I should still not use it?
Shoot, guy, I wouldn't presume to advise you, other than make sure your various servers implement it. I don't use it, but I'm not concerned with SEO.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 9:22 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC