Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. 🚫 No AI-generated (LLM) posts allowed. Share your own thoughts and experience — accounts may be terminated for violations.

PHP Rewrite Question on Folder Levels

Status
Not open for further replies.
Joined
Apr 26, 2005
Posts
7,414
Reaction score
151
Guys

I'm spending the afternoon integrating Price Tapestry into my own set of template files.

On this search page the header and main menu are includes from my own template as follows:

Code:
include("inc-title.php");
include("inc-menu-main.php");

Now I want to add the same things to the merchants page. Now, I've added exactly the same code, but the images are broken. I think that this is because the merchants page is being displayed using the ReWrite engine, with the following rules:

Code:
RewriteRule ^merchant/$ merchants.php
RewriteRule ^merchant/(.*)/$ search.php?q=merchant:$1:&rewrite=1%{QUERY_STRING} [L]
RewriteRule ^merchant/(.*)/(.*).html$ search.php?q=merchant:$1:&page=$2&rewrite=1%{QUERY_STRING} [L]

Now, I am of course just about to read up on the ReWrite engine, but can one of you clever people tell me what to do before I work it out? Currently images are getting broken by the insertion of a merchant folder, i.e.

Code:
http://www.kingsizebeds.me.uk/merchant/images/logo-260x60.jpg

which should be:

Code:
http://www.kingsizebeds.me.uk/images/logo-260x60.jpg

Any ideas?

Thanks
 
Sounds to me more like the inc-title and inc-main-menu files need changing so that the urls to images are absolute, instead of relative?
 
I can put a slash in front of the image src in the included file, i.e. change:

Code:
<td width="280"><a href="index.php"><img src="images/logo-260x60.jpg" alt="Home Page" width="260" height="60" border="0" /></a></td>

to:

Code:
<td width="280"><a href="index.php"><img src="/images/logo-260x60.jpg" alt="Home Page" width="260" height="60" border="0" /></a></td>

and the image will display. However, the link to the home page is still broken, and also the stylesheet is not referenced properly. I think there will be a more sophisticated solution by adding more info to the ReWrite rules ...

Thanks
 
and the image will display. However, the link to the home page is still broken, and also the stylesheet is not referenced properly. I think there will be a more sophisticated solution by adding more info to the ReWrite rules ...

Thanks

Only if you write a rule that converts the

/merchant/images/...

back to

/images/...

But you'd have to do that for any further folders you create with mod_rewrite and wouldn't be considered normal practice.
 
Any links in the included file also get rewritten and break the link, e.g. for the Contact Us link I have:

http://www.kingsizebeds.me.uk/merchant/site-enquiry.php

when I want:

http://www.kingsizebeds.me.uk/site-enquiry.php

So I guess the question is how do I turn off the insertion of "merchant/" into any file location references in the file being included.

Thanks

You can't turn off the insertion, there isn't any.

The link is <a href="site_enquiry.php">, the browser treats that as a relative url, so in this instance relative to the merchant folder. You need to change all urls (hyperlinks, css, images, javascript) to be absolute.
 
Status
Not open for further replies.

Rule #1: Be Respectful

Do not insult any other member. Be polite and do business. Thank you!

Premium Members

New Threads

Domain Forum Friends

Lastest Listings

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators
General chit-chat
Help Users
  • No one is chatting at the moment.
  • Siusaidh AcornBot:
    Siusaidh has left the room.
      Siusaidh AcornBot: Siusaidh has left the room.
      Top Bottom