01-19-04 12:19 PM
listbot@gmx.de wrote:
quote:
> On Fri, 28 Nov 2003 12:45:49 +0100, listbot@gmx.de wrote:
>
>
>
>
>
> ok, i just found [QSA]
>
> the only problem now O have is, that directories in that request
> should be removed, so relative links still work. Example:
>
> with
>
> RewriteRule ([^/]+).html /index.php?url=$1 [QSA]
>
>
> some_page.html calls index.php?url=page
>
> but
>
> /somedir/somepage.html
>
> tries to get relativ links from /somedir/
>
> how can I change this?
Get rid of the relative links. The quickest way (not necessarily the
best) of doing it is to have your php script filter through all the href
and scr attributes and correct them if they are relative. Something
similar to this:
so, at the top of index.php, use: ob_start();
Then at the bottom after all the output, use:
<?php
$content=ob_get_contents();
ob_end_clean();
$site_root='/';
preg_match_all('/(src|href)="([^"]*)"/is',$content,$matches);
$search=array();
$replace=array();
foreach($matches[2] as $i=>$match){
if(substr($match,0,4)!='http' || substr($match,0,1)!='/'){
// if the link doesn't start with 'http' or '/', do this
$search[$i]=$matches[0][$i];
$replace[$i]=$matches[1][$i].'="'.$site_root.$match.'"';
}
}
echo str_replace($search,$replace,$content);
?>
HTH
--
Justin Koivisto - spam@koivi.com
PHP POSTERS: Please use comp.lang.php for php related questions,
alt.php* groups are not recommended.
[ Post a follow-up to this message ]
|