![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Jul 2005
Posts: 62
Rep Power: 4
![]() |
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. |
|
|
|
|
|
#2 |
|
Programming Guru
![]() |
Not sure what you're saying, but try "/image/bg.gif". This sounds more like an HTML issue.
__________________
|
|
|
|
|
|
#3 |
|
Expert Programmer
Join Date: May 2005
Location: East Lansing, MI
Posts: 663
Rep Power: 4
![]() |
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?
|
|
|
|
|
|
#4 |
|
Troll
Join Date: Apr 2005
Location: Texas
Posts: 732
Rep Power: 4
![]() |
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 |
|
|
|
|
|
#5 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
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 |
|
|
|
|
|
#6 |
|
Programmer
Join Date: Jul 2005
Posts: 62
Rep Power: 4
![]() |
@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. |
|
|
|
|
|
#7 | |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Quote:
__________________
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 |
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|