PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > alt.apache.configuration > mod_rewrite and relative paths
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
alt.apache.configuration Apache web server configuration issues.

mod_rewrite and relative paths

Réponse
 
LinkBack Outils de la discussion
Vieux 19/02/2007, 11h39   #1
Susanne West
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut mod_rewrite and relative paths



hi group.


i've been using mod_rewrite for simple things so
far and always encountered the same (basic) problem,
which is, that relative paths get messed up.

i was wondering if i'm doing something conceptionally wrong
if i use the following setup:



i have multiple (empty!) directories on my disk that i'd like
to use as 'virtual' urls (e.g.):

/about
/products
/detail

as well as a special directory with a handler-script
/frontend/handler.php
that should be targeted by .htaccess-files in the directories
above. so each directory listed contains a .htaccess file with
the following (accordingly adapted) lines:

RewriteEngine On
RewriteBase /about/
RewriteRule .* /frontend/handler.php?mode=about
RewriteRule ^index.html$ /frontend/handler.php?mode=about

is that a correct way to handle the overall situation?
because the problem arises, when i'd like to additionally map an
exception from another level of the path hierarchy, like mapping the
actual homepage [/index.html] down to /frontend/handler.php?mode=home
because obviously, then, the relative links to images, stylesheets etc
are different and the page looks totally broken...

how are you guys handling this?


greets!



  Réponse avec citation
Vieux 19/02/2007, 23h35   #2
shimmyshack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mod_rewrite and relative paths

On 19 Feb, 11:39, Susanne West <s...@gmx.de> wrote:
> hi group.
>
> i've been using mod_rewrite for simple things so
> far and always encountered the same (basic) problem,
> which is, that relative paths get messed up.
>
> i was wondering if i'm doing something conceptionally wrong
> if i use the following setup:
>
> i have multiple (empty!) directories on my disk that i'd like
> to use as 'virtual' urls (e.g.):
>
> /about
> /products
> /detail
>
> as well as a special directory with a handler-script
> /frontend/handler.php
> that should be targeted by .htaccess-files in the directories
> above. so each directory listed contains a .htaccess file with
> the following (accordingly adapted) lines:
>
> RewriteEngine On
> RewriteBase /about/
> RewriteRule .* /frontend/handler.php?mode=about
> RewriteRule ^index.html$ /frontend/handler.php?mode=about
>
> is that a correct way to handle the overall situation?
> because the problem arises, when i'd like to additionally map an
> exception from another level of the path hierarchy, like mapping the
> actual homepage [/index.html] down to /frontend/handler.php?mode=home
> because obviously, then, the relative links to images, stylesheets etc
> are different and the page looks totally broken...
>
> how are you guys handling this?
>
> greets!


If you just used
ReWriteBase /
ReWriteCond !-f
ReWriteCond !-d
RewriteRule . /frontend/handler.php

and then used the value of $_SERVER['REQUEST_URI']
you would be able to get all the info you needed, pasrsing the url
will get you all the info into an array and then you can make the
paths that you need to send and prepend them.

My advice is to steer clear of relative urls in your html. What's the
use of context driven resources (ie, ../../../../images/static/2.jpg,
when you could just have /images/static/2.jpg - this way when you move
your css directory you don't have a headache.



  Réponse avec citation
Vieux 19/02/2007, 23h36   #3
shimmyshack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mod_rewrite and relative paths

On 19 Feb, 11:39, Susanne West <s...@gmx.de> wrote:
> hi group.
>
> i've been using mod_rewrite for simple things so
> far and always encountered the same (basic) problem,
> which is, that relative paths get messed up.
>
> i was wondering if i'm doing something conceptionally wrong
> if i use the following setup:
>
> i have multiple (empty!) directories on my disk that i'd like
> to use as 'virtual' urls (e.g.):
>
> /about
> /products
> /detail
>
> as well as a special directory with a handler-script
> /frontend/handler.php
> that should be targeted by .htaccess-files in the directories
> above. so each directory listed contains a .htaccess file with
> the following (accordingly adapted) lines:
>
> RewriteEngine On
> RewriteBase /about/
> RewriteRule .* /frontend/handler.php?mode=about
> RewriteRule ^index.html$ /frontend/handler.php?mode=about
>
> is that a correct way to handle the overall situation?
> because the problem arises, when i'd like to additionally map an
> exception from another level of the path hierarchy, like mapping the
> actual homepage [/index.html] down to /frontend/handler.php?mode=home
> because obviously, then, the relative links to images, stylesheets etc
> are different and the page looks totally broken...
>
> how are you guys handling this?
>
> greets!


just in case that wasnt clear:

<Directory "/path/to/vhosts/server.com/public">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /frontend/handler.php [L,NS]
</Directory>

  Réponse avec citation
Vieux 20/02/2007, 08h40   #4
Susanne West
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mod_rewrite and relative paths

shimmyshack wrote:
> On 19 Feb, 11:39, Susanne West <s...@gmx.de> wrote:
>
>>hi group.
>>
>>i've been using mod_rewrite for simple things so
>>far and always encountered the same (basic) problem,
>>which is, that relative paths get messed up.
>>
>>i was wondering if i'm doing something conceptionally wrong
>>if i use the following setup:
>>
>>i have multiple (empty!) directories on my disk that i'd like
>>to use as 'virtual' urls (e.g.):
>>
>> /about
>> /products
>> /detail
>>
>>as well as a special directory with a handler-script
>> /frontend/handler.php
>>that should be targeted by .htaccess-files in the directories
>>above. so each directory listed contains a .htaccess file with
>>the following (accordingly adapted) lines:
>>
>> RewriteEngine On
>> RewriteBase /about/
>> RewriteRule .* /frontend/handler.php?mode=about
>> RewriteRule ^index.html$ /frontend/handler.php?mode=about
>>
>>is that a correct way to handle the overall situation?
>>because the problem arises, when i'd like to additionally map an
>>exception from another level of the path hierarchy, like mapping the
>>actual homepage [/index.html] down to /frontend/handler.php?mode=home
>>because obviously, then, the relative links to images, stylesheets etc
>>are different and the page looks totally broken...
>>
>>how are you guys handling this?
>>
>>greets!

>
>
> If you just used
> ReWriteBase /
> ReWriteCond !-f
> ReWriteCond !-d
> RewriteRule . /frontend/handler.php
>
> and then used the value of $_SERVER['REQUEST_URI']
> you would be able to get all the info you needed, pasrsing the url
> will get you all the info into an array and then you can make the
> paths that you need to send and prepend them.
>
> My advice is to steer clear of relative urls in your html. What's the
> use of context driven resources (ie, ../../../../images/static/2.jpg,
> when you could just have /images/static/2.jpg - this way when you move
> your css directory you don't have a headache.
>
>
>



thanks for your suggestion. i will try that.

there is one drawback with your proposal of top-down urls such as
(/images/statis/2.jpg): i'm using a development system that (might)
have another base-url-path. like so:

development: 127.0.0.1/project_x/images/2.jpg
vs
productive: www.project_x.com/images/2.jpg

with relative urls, this is never a problem because the tree maps
from the given starting point. if you go top-down, you'd have to
rely on the base being the same...

greets.
  Réponse avec citation
Vieux 20/02/2007, 11h37   #5
shimmyshack
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mod_rewrite and relative paths

On 20 Feb, 08:40, Susanne West <s...@gmx.de> wrote:
> shimmyshack wrote:
> > On 19 Feb, 11:39, Susanne West <s...@gmx.de> wrote:

>
> >>hi group.

>
> >>i've been using mod_rewrite for simple things so
> >>far and always encountered the same (basic) problem,
> >>which is, that relative paths get messed up.

>
> >>i was wondering if i'm doing something conceptionally wrong
> >>if i use the following setup:

>
> >>i have multiple (empty!) directories on my disk that i'd like
> >>to use as 'virtual' urls (e.g.):

>
> >> /about
> >> /products
> >> /detail

>
> >>as well as a special directory with a handler-script
> >> /frontend/handler.php
> >>that should be targeted by .htaccess-files in the directories
> >>above. so each directory listed contains a .htaccess file with
> >>the following (accordingly adapted) lines:

>
> >> RewriteEngine On
> >> RewriteBase /about/
> >> RewriteRule .* /frontend/handler.php?mode=about
> >> RewriteRule ^index.html$ /frontend/handler.php?mode=about

>
> >>is that a correct way to handle the overall situation?
> >>because the problem arises, when i'd like to additionally map an
> >>exception from another level of the path hierarchy, like mapping the
> >>actual homepage [/index.html] down to /frontend/handler.php?mode=home
> >>because obviously, then, the relative links to images, stylesheets etc
> >>are different and the page looks totally broken...

>
> >>how are you guys handling this?

>
> >>greets!

>
> > If you just used
> > ReWriteBase /
> > ReWriteCond !-f
> > ReWriteCond !-d
> > RewriteRule . /frontend/handler.php

>
> > and then used the value of $_SERVER['REQUEST_URI']
> > you would be able to get all the info you needed, pasrsing the url
> > will get you all the info into an array and then you can make the
> > paths that you need to send and prepend them.

>
> > My advice is to steer clear of relative urls in your html. What's the
> > use of context driven resources (ie, ../../../../images/static/2.jpg,
> > when you could just have /images/static/2.jpg - this way when you move
> > your css directory you don't have a headache.

>
> thanks for your suggestion. i will try that.
>
> there is one drawback with your proposal of top-down urls such as
> (/images/statis/2.jpg): i'm using a development system that (might)
> have another base-url-path. like so:
>
> development: 127.0.0.1/project_x/images/2.jpg
> vs
> productive:www.project_x.com/images/2.jpg
>
> with relative urls, this is never a problem because the tree maps
> from the given starting point. if you go top-down, you'd have to
> rely on the base being the same...
>
> greets.


well, if you are only doing markup, the its a valid method, but ways
exits to get the document root, and even the root of the application -
if you place it somewhere other than the doc root.
define( STR_APPLICATION_ROOT, dirname( _FILE_ ) );
#takes approx 0.0001 seconds to return the value inside your
config.inc.php file for the app.

download phpmyadmin or wordpress and so on, and se how they deal with
the multiplatform problem.

THe reason why it pays to actually know what these values are is that
you can keep part of your application out of the reach of prying eyes
by storing it in the /private/ directory
this way you cannot use ../../private because of the problem you
mention - you never know where the actual root of the site will be and
where private will be compared to that. But you can use the
dirname( _FILE_ ) method to find where things are or
dirname($_SERVER['SCRIPT_FILENAME'])
and so on... So while html might be ok with relative paths, it is
better to get the real paths from the underlying OS when writing a
complex php app.

I have a config.inc.php which includes path, environmental, language
and other settings for that system, and the rest of the app inherits
from that. You can then restructure your code and just change one
variable

  Réponse avec citation
Vieux 20/02/2007, 12h51   #6
Susanne West
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mod_rewrite and relative paths

shimmyshack wrote:
> On 20 Feb, 08:40, Susanne West <s...@gmx.de> wrote:
>
>>shimmyshack wrote:
>>
>>>On 19 Feb, 11:39, Susanne West <s...@gmx.de> wrote:

>>
>>>>hi group.

>>
>>>>i've been using mod_rewrite for simple things so
>>>>far and always encountered the same (basic) problem,
>>>>which is, that relative paths get messed up.

>>
>>>>i was wondering if i'm doing something conceptionally wrong
>>>>if i use the following setup:

>>
>>>>i have multiple (empty!) directories on my disk that i'd like
>>>>to use as 'virtual' urls (e.g.):

>>
>>>> /about
>>>> /products
>>>> /detail

>>
>>>>as well as a special directory with a handler-script
>>>> /frontend/handler.php
>>>>that should be targeted by .htaccess-files in the directories
>>>>above. so each directory listed contains a .htaccess file with
>>>>the following (accordingly adapted) lines:

>>
>>>> RewriteEngine On
>>>> RewriteBase /about/
>>>> RewriteRule .* /frontend/handler.php?mode=about
>>>> RewriteRule ^index.html$ /frontend/handler.php?mode=about

>>
>>>>is that a correct way to handle the overall situation?
>>>>because the problem arises, when i'd like to additionally map an
>>>>exception from another level of the path hierarchy, like mapping the
>>>>actual homepage [/index.html] down to /frontend/handler.php?mode=home
>>>>because obviously, then, the relative links to images, stylesheets etc
>>>>are different and the page looks totally broken...

>>
>>>>how are you guys handling this?

>>
>>>>greets!

>>
>>>If you just used
>>>ReWriteBase /
>>>ReWriteCond !-f
>>>ReWriteCond !-d
>>>RewriteRule . /frontend/handler.php

>>
>>>and then used the value of $_SERVER['REQUEST_URI']
>>>you would be able to get all the info you needed, pasrsing the url
>>>will get you all the info into an array and then you can make the
>>>paths that you need to send and prepend them.

>>
>>>My advice is to steer clear of relative urls in your html. What's the
>>>use of context driven resources (ie, ../../../../images/static/2.jpg,
>>>when you could just have /images/static/2.jpg - this way when you move
>>>your css directory you don't have a headache.

>>
>>thanks for your suggestion. i will try that.
>>
>>there is one drawback with your proposal of top-down urls such as
>>(/images/statis/2.jpg): i'm using a development system that (might)
>>have another base-url-path. like so:
>>
>> development: 127.0.0.1/project_x/images/2.jpg
>> vs
>> productive:www.project_x.com/images/2.jpg
>>
>>with relative urls, this is never a problem because the tree maps
>>from the given starting point. if you go top-down, you'd have to
>>rely on the base being the same...
>>
>>greets.

>
>
> well, if you are only doing markup, the its a valid method, but ways
> exits to get the document root, and even the root of the application -
> if you place it somewhere other than the doc root.
> define( STR_APPLICATION_ROOT, dirname( _FILE_ ) );
> #takes approx 0.0001 seconds to return the value inside your
> config.inc.php file for the app.
>
> download phpmyadmin or wordpress and so on, and se how they deal with
> the multiplatform problem.
>
> THe reason why it pays to actually know what these values are is that
> you can keep part of your application out of the reach of prying eyes
> by storing it in the /private/ directory
> this way you cannot use ../../private because of the problem you
> mention - you never know where the actual root of the site will be and
> where private will be compared to that. But you can use the
> dirname( _FILE_ ) method to find where things are or
> dirname($_SERVER['SCRIPT_FILENAME'])
> and so on... So while html might be ok with relative paths, it is
> better to get the real paths from the underlying OS when writing a
> complex php app.
>
> I have a config.inc.php which includes path, environmental, language
> and other settings for that system, and the rest of the app inherits
> from that. You can then restructure your code and just change one
> variable
>



word!!! you are absolutely right! i have a global config file
which switches between development and integration systems and
actually, all i had to do, was to prepend my $urlbase variable
that carries '/' or then '/project_x/' instead of the relative
path ("../") et voila... thanks for pushing me there. i was
completely blindfolded by my own system & logic...

that's the way to go and definately better than to go regex in
any PHP_SELF (or so) env-variable...


greets...




  Réponse avec citation
Vieux 21/02/2007, 21h34   #7
Jim Carlock
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: mod_rewrite and relative paths

"shimmyshack" stated...
: if you are only doing markup, then it is a valid method,
: but ways exist to get the document root, and even the
: root of the application - if you place it somewhere other
: than the doc root.
:

<apache_code>
define( STR_APPLICATION_ROOT, dirname( _FILE_ ) );
# takes approx 0.0001 seconds to return the value inside
# your config.inc.php file for the app.
</apache_code>

Perhaps another way involves using Alias and the following
Apache code (inside httpd.conf)...

<IfModule mod_alias.c>
Alias /shared/ "C:/htdocs/www/root/shared/"

<Directory "C:/htdocs/www/root/shared">
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</IfModule>

The above sets up a shared folder and it gets placed in the
httpd.conf file. Works well for a conglomeration of virtual
hosts where you want to share a specific folder in all hosts.

The corresponding PHP code...

//
// The shared folder holds a file named news.php that all
// virtual hosts can call upon and run.
//
// filename returns the whole path to the file and this works
// well PHP include() and require() functions.
//
$oNews = apache_lookup_uri('/shared/news.php');
$sPathToNews = $oNews->filename;
require($sPathToNews);

The above was implemented and tested with Apache 1.334
and 1.337 running on Windows XP in the year, 2006. Two
versions of PHP were tested successfully, PHP 4.3x & 5.2x.

I'm looking for some more with mod_rewrite myself. If
anyone knows of any ful things they can throw my way,
that would be greatly appreciated. Thanks!

--
Jim Carlock
Post replies to the group.


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 20h31.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,23394 seconds with 15 queries