Clean URLs seem to have the side effect of making relative paths in images and links not work, because they use the clean URL as the base path.
I am looking for clean solutions for this. I have tried both adding a <base> tag with the true base path to the <head> and inserting the base path into every image/link with using templates. Both of these require templates. I am looking for a solution that will make code portable, so that you can put it in any subdirectory on a website and it just works.
Are there other solutions to this problem?
Clean URLs and Relative Paths
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Clean URLs and Relative Paths
(#10850)
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
So did I pick a topic with the perfect combination of obscurity and monotony? 
I am still searching. I looked into the HTTP headers Content-Location and Content-Base. Setting either of them did not have the same effect as the <base> tag in the header. Does anyone have experience using those headers?
I am still searching. I looked into the HTTP headers Content-Location and Content-Base. Setting either of them did not have the same effect as the <base> tag in the header. Does anyone have experience using those headers?
(#10850)
what's wrong with using relative path. I think this is the easiest way to be able to put the project in any directory.
for example:
for example:
Code: Select all
<img src="images/xoxo.png" />- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Nothing and I prefer to do it that way. The problem comes when rewriting for clean URLs.jmut wrote:what's wrong with using relative path. I think this is the easiest way to be able to put the project in any directory.
It is a little convoluted, but let me try to explain. Say you have a Front Controller script at "www.mysite.com/admin/index.php" and you want all your images in the "admin" area to be relative -- ok so far. But then you want clean URLs like "www.mysite.com/admin/users/list/". The rewrite rules run "/admin/index.php" and set PATH_INFO to "/users/list/", but because of the clean URL the base directory (for relative images and URLs) is set to "www.mysite.com/admin/users/list/" so none of the images in "www.mysite.com/admin/images/" referenced using "images/myimage.png" appear because the web server is looking in "www.mysite.com/admin/users/list/images/".
(#10850)
- Ambush Commander
- DevNet Master
- Posts: 3698
- Joined: Mon Oct 25, 2004 9:29 pm
- Location: New Jersey, US
I've often had this problem, which at first made me avoid folders like the plague. I believe absolute is the only way to go (the leading slash). One thing to note is that if you plan on letting the application coexist with another on the same domain, by putting them in different folders, you'll have to make the part right before the leading slash configurable, i.e.
/Main_Page/Part_1 might be the link for a site only on that software, but
/wiki/Main_Page/Part_1 might be the link for a site that is using multiple software
/Main_Page/Part_1 might be the link for a site only on that software, but
/wiki/Main_Page/Part_1 might be the link for a site that is using multiple software
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Unfortunately I need the code to be portable form development to staging to production URLs which can be almost any variation of different servers or directory paths. I have come down to putting a <base> tag in the header and having the Response object set the base URL for the site from the value in the current configuration:
I had hoped that adding one of the Content-* headers would work because that would have been transparent to any application code. Now the app needs to set the <base> tag somewhere.
Code: Select all
<base href="{BASE}"/>
becomes
<base href="http://www.mysite.com/path/to/site/"/>(#10850)