Forum Moderators: coopster

Message Too Old, No Replies

PHP & HTACCESS for semi-dynamic content

         

stidj

5:14 am on Oct 13, 2003 (gmt 0)

10+ Year Member



Hi guys. This is my first post here.

I'm currently using an htaccess redirect to my index.php which automatically includes any html file. My problem is that the relative path is always '/' so if I go to site.com/dir/page.htm and in page.htm I have a reference to "image.jpg" it assumes the true path is '/image.jpg' forcing me to use absolute links in every case which I would like to avoid.

The only solution I can think of, which I don't like is to use PHP and parse $REQUEST_URI and use the PHP function that changes the current working directory.

Does anyone know a way to still redirect to the script below but have the current working directory be whatever is in $REQUEST_URI?

Options +FollowSymLinks
RewriteEngine on
RewriteRule!\.(gif¦jpg¦png¦css)$ /home/virtual/site187/fst/var/www/html/index.php

gethan

9:08 am on Oct 13, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Stidj

Firstly welcome to WebmasterWorld.

From what I understand of your problem the rule you would require using mod_rewrite would be:

RewriteEngine on
RewriteRule!\.(gif¦jpg¦png¦css¦php)$ /index.php

The php needs to be there to stop a recursive rule - eg. request for index.php are rewritten to index.php and on...

Your other option is to use a handler for all files of a certain extension - eg. .html

Action default /index.php
AddHandler default .html

You'll have to come up with something for the directories but should set you on the right path.

HTH

stidj

6:57 pm on Oct 19, 2003 (gmt 0)

10+ Year Member



Thanks gethan but I have already basically set things up but they aren't the way I want them to be.

Since the rewrite rule goes to /home/virtual/site187/fst/var/www/html/index.php

the relative dir is always / and I don't like that
because if you go to /access/index.html

I would like the relative dir to always be whatever dir is referred to in $REQUEST_URI

if a link in index.html refers to "image.jpg" it looks for it in /image.jpg but I would like it to work so it looks in the REQUEST URI for the link. So in this case the relative link should be in "/access/image.jpg" instead of the way it currently works "/image.jpg"

Do you guys know a simple way around this?

I have also noticed there is no trailing slash automatically added now that I use htaccess. If I don't use htaccess my server does automatically add the trailing slash so I'm not sure what to do about this.