Welcome to WebmasterWorld Guest from 54.196.175.173

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Mod_Rewrite Help

Images and Linking

     

xcandyman

1:19 pm on Aug 13, 2003 (gmt 0)

10+ Year Member



Hi all

I have now managed to get my head round some of the mod_rewrite functions. I have managed to link a dynamic page to html

e.g RewriteRule ^([0-9]+)/([0-9]+).html index.php?year=$1&month=$2

but by putting a new folder in the path all my pages with images on they all all dead because they are now looking at:

www.widgets.com/createdurl/?

when the images are at:

widgets.com/?

What can I do?

Thanks

Steve

waitman

1:55 pm on Aug 13, 2003 (gmt 0)

10+ Year Member



Hello

I am not sure I understand your question.

Are you saying that a page like

[freakinexample.com...]

has messed up relative links to images?

a) if you stick with your existing rewrite, you should probably not use the forward slash to separate the year and month, perhaps pick another character.

b) i suggest you send all html requests to your index.php script, in index.php look at REQUEST_URI to decide what content to send back. if you only want "calendar" requests, change your rewrite to something like this:

RewriteCond %{REQUEST_URI} ^/calendar/(.+)\.html$
RewriteRule ^/calendar/(.+)\.html$ /calendar/index.php?page=$1

I played a little with this.

here is my script

<?php

$request = $_SERVER['REQUEST_URI'];
$broken = @explode('/',str_replace('.html','',$request));

$numberbroken=count($broken);
$dir = '/calendar';
$img = 'foolio/funfun.jpg';

$date=date('Y/m');
if ($numberbroken>2)
{
$date = date('Y/m',strtotime(intval($broken[$numberbroken-1]).'/1/'.intval($broken[$numberbroken-2])));
array_pop($broken);
array_pop($broken);
$dir=join('/',$broken);
}
echo $date;
echo '<br>'.$dir;
echo '<br>'.$dir.'/'.$img;
?>

[secure.activesell.com...]

here are the results

2002/06
/calendar/swdaweffw/34234
/calendar/swdaweffw/34234/foolio/funfun.jpg

I calculate the relative image location for the <img> tag in index.php, you can tinker around with that if you like.

Hope that helps.

jdMorgan

2:12 pm on Aug 13, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Steve,

A couple of questions:

Where did "/createdurl" come from?

Have you tried using a leading slash on "index"?
RewriteRule ^([0-9]+)/([0-9]+).html /index.php?year=$1&month=$2

It's likely that you can fix this problem by adding a RewriteCond, by adding a second RewriteRule, by using RewriteBase, or by some combination of these.

Jim

waitman

2:23 pm on Aug 13, 2003 (gmt 0)

10+ Year Member



Hello

My opinion is that the forward slash used to separate the year and the month is messing up relative links to images.

ex: if your uri is "/04/03.html" and you have a relative reference to an image on the page "images/doh.jpg", the browser will ask the server for "/04/images/doh.jpg"

a simple fix for this problem might be to always use absolute references "/images/doh.jpg"

Whenever I start a new project using mod_rewrite I usually avoid the directories nightmare and flatten everything that goes through rewrite.

Take care,

xcandyman

2:55 pm on Aug 13, 2003 (gmt 0)

10+ Year Member



Where did "/createdurl" come from?

its the folder the first folder ^([0-9]+)/ creates.

Have you tried using a leading slash on "index"?

I get a 404

It's likely that you can fix this problem by adding a RewriteCond, by adding a second RewriteRule, by using RewriteBase, or by some combination of these.

Im not sure how to do this.

Thanks

jdMorgan

4:18 pm on Aug 13, 2003 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Steve,

> Im not sure how to do this.

I can't tell you specifically, because I'm not familiar at all with your directory structure, or where you have installed the mod_rewrite rules, or what other rules might be present. This is "detail work" and such details are critical to an understanding of the problem, and to offering any relevant advice or solutions.

You can choose to re-structure your directories or use absolute image URLs, as proposed by waitman, or you can add more rules or refine your existing ones to fix or to avoid the problem. That choice depends on the details.

If the images are now being requested relative to a new subdirectory, you might - for example - simply strip the subdirectory name from all dynamically-invoked image requests using something like this:
RewriteRule ^[0-9]+/(.+)\.(gif¦jpe?g¦png) /local_path_to_your_images_from_web_root/$1.$2 [L]

(As usual, remember that posting on this board modifies the pipe character; You'll have to edit the code above to change "¦" to a solid vertical pipe character before trying to use it.)

Jim

 

Featured Threads

Hot Threads This Week

Hot Threads This Month