.htaccess question

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

.htaccess question

Post by intellivision »

How to have a web directory think it's the site root, so that I can path images and hyperlinks anywhere under it to "/"?

Example of file structure:

Code: Select all

www/site1/site1-dev/images/image.jpg
Example of html I'm trying to use:

Code: Select all

<img src="/images/image.jpg" />
So I'd put an .htaccess file in site1-dev/ (right?) and what would its syntax be?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: .htaccess question

Post by superdezign »

intellivision wrote:So I'd put an .htaccess file in site1-dev/ (right?) and what would its syntax be?
You can put an .htaccess file anywhere.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

Not sure you'd even need an .htaccess file. I remember something about a BASE HREF tag that did just that.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
miro_igov
Forum Contributor
Posts: 485
Joined: Fri Mar 31, 2006 5:06 am
Location: Bulgaria

Post by miro_igov »

<base> will not help if the file is not in the web root.

If you are able to access the image through http://domain.com/path/to/image.jpeg, then you can use the <base>
If the image is not in the web root you can add it's directory as alias in the apache config (valid only if you use apache)
intellivision
Forum Commoner
Posts: 83
Joined: Mon Aug 22, 2005 1:25 am
Location: Orbit

Post by intellivision »

Sorry guys, I should have been more clear. What I'd like to do is dev or test at a lower level directory like www/site1/site1-dev/ then move the files up to the production directory www/site1/ without having to change paths. Not just images, but anchor tags and others.

So that's what got me thinking that there's probably some way to get an .htaccess file in the dev directory make the web app think it's at root.
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Why not use relative urls instead of absolute?

<img href="/images/logo.gif"> becomes
<img href="images/logo.gif">

Other than that, the <base> tag will be what you want.
Post Reply