Hi all!
I'm using URL rewriting to change that:
http://www.example.com/word/an-other-word/yet-another
into:
http://www.example.com/index.php?var1=a ... et-another
The rewriting works good. The problem I have is with the working directory of my php file.
When I type directly http://www.example.com/index.php?var1=a ... et-another, I can include images files with relative links, such as "src=images/image.gif".
But when I type http://www.example.com/index.php?var1=a ... et-another, it's not working, I have to use absolute link (src="/images/image.gif") or a relative link such as "src=../../images/image.gif".
I'd prefer to use relative links, because it's handier to move a whole directory to a sub-directory on a server (a /beta/ to test it before releasing for example).
Is there a way to solve my problem?
Thanks a lot!
Working Directory when using URL rewriting
Moderator: General Moderators
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Ok, that's what I was thinking about. So I suppose I have to use this workaround, and there is no simple solution... I'll have to change all my urls to images, css and local pages, then.
My pages will become quite ugly, I'll have to add lots of "<?php echo $dir; ?>" ....
Thanks Everah for the answer!
My pages will become quite ugly, I'll have to add lots of "<?php echo $dir; ?>" ....
Thanks Everah for the answer!
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
Let me get a little more specific. I usually create a function and a constant. The constant gets information from either a configuration file or from the settings in a database. It tells my script whether to use friendly or actual URLS. In the function, I pass to it the URL. The function then checks the URL type constant and returns the URL. Then I reference the function in my scripts.
This is an oversimplified example, but it is essentially what I do.
Code: Select all
<a href="<?php print_url('aboutus'); ?>" title="Some Title">About Us</a>