PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Hébergement serveur > comp.info.servers.unix > Yep another mod_rewrite question!
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.info.servers.unix Web servers for UNIX platforms.

Yep another mod_rewrite question!

Réponse
 
LinkBack Outils de la discussion
Vieux 06/08/2006, 01h27   #1
Leo Andrews
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Yep another mod_rewrite question!

Hi,

mod_rewrite really is a hassle to get to grips with and I've been using
it on and off for years. Anyhow the pro's outweigh the con's a
hundred-fold so we'll stick with it.

I'm trying to set up a rewrite so that if you have a url along the lines
of http://www.mysite.com/features/1/10/ that will redirect to a handler
script and pass the 1 and the 10.

That was easy and this does it...
RewriteRule ^(.*)/(.*)/ /features/feature.php?id=$1&p=$2 [L]

Now what if the entered URL is http://www.mysite.com/features/1/10 (note
the omission of the trailing slash). That would need to redirect to
http://www.mysite.com/features/1/10/ before being handled by the
previous rule. However it doesn't work with

RewriteRule ^(.*)/(.*)$ /features/$1/$2/ [R]

The .htaccess is residing in the features folder and SymLinks is on etc.
Can anyone see where I'm going wrong? This should be so easy!

Many thanks in advance to anyone who can !

Leo
  Réponse avec citation
Vieux 06/08/2006, 08h58   #2
Mads Toftum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Yep another mod_rewrite question!

On Sun, 06 Aug 2006 01:27:17 +0100, Leo Andrews <leo@invalid.syntax> wrote:
> mod_rewrite really is a hassle to get to grips with and I've been using
> it on and off for years. Anyhow the pro's outweigh the con's a
> hundred-fold so we'll stick with it.


There's even a book out about mod_rewrite now.
The Definitive Guide to Apache mod_rewrite (Rich Bowen)
http://www.apress.com/book/bookDisplay.html?bID=10030
>
> I'm trying to set up a rewrite so that if you have a url along the lines
> of http://www.mysite.com/features/1/10/ that will redirect to a handler
> script and pass the 1 and the 10.
>
> That was easy and this does it...
> RewriteRule ^(.*)/(.*)/ /features/feature.php?id=$1&p=$2 [L]
>

Careful - .* could match a lot more than you want it to match. A much
clearer solution would be something like: ^([0-9]+)/([0-9]+)/?$
Note that this also solves the problem below by making the last /
optional.
Or if it is not just numbers, but also other chars between the /es,
then use [^/] instead of [0-9].

> Now what if the entered URL is http://www.mysite.com/features/1/10 (note
> the omission of the trailing slash). That would need to redirect to
> http://www.mysite.com/features/1/10/ before being handled by the
> previous rule. However it doesn't work with
>
> RewriteRule ^(.*)/(.*)$ /features/$1/$2/ [R]
>

Since .* will also match /, you could end up with // trailing that url.

> The .htaccess is residing in the features folder and SymLinks is on etc.
> Can anyone see where I'm going wrong? This should be so easy!
>

RewriteLog and RewriteLogLevel 9 is the easy way to figure out what is
going wrong.

vh

Mads Toftum
  Réponse avec citation
Vieux 06/08/2006, 11h14   #3
HansH
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Yep another mod_rewrite question!

"Leo Andrews" <leo@invalid.syntax> schreef in bericht
news:44d5369d$0$139$7b0f0fd3@reader.news.newnet.co .uk...
> I'm trying to set up a rewrite so that if you have a url along the lines
> of http://www.mysite.com/features/1/10/ that will redirect to a handler
> script and pass the 1 and the 10.
>
> That was easy and this does it...
> RewriteRule ^(.*)/(.*)/ /features/feature.php?id=$1&p=$2 [L]
>
> Now what if the entered URL is http://www.mysite.com/features/1/10 (note
> the omission of the trailing slash). That would need to redirect to
> http://www.mysite.com/features/1/10/ before being handled by the
> previous rule. However it doesn't work with

Please specify: does nothing, work partial, return error at server or
browser
>
> RewriteRule ^(.*)/(.*)$ /features/$1/$2/ [R]

Why telling the _browser_ to retry with trailing slash?

> The .htaccess is residing in the features folder and SymLinks is on etc.
> Can anyone see where I'm going wrong? This should be so easy!

Try
RewriteRule ^(\d+)/(\d+)/?$ /features/feature.php?id=$1&p=$2 [L]

The trailing slash is optional, adding a ? will allow it to be missing.
However, good chance mod_dir will kick in before your htaccess is processed.

The \d-s restrict input to numerics only, resulting in a good old 404
response to 'illegal' values.
The + makes one digit mandatory, while allowing more. Most probably you'll
never see zero digits: IIRC apache collapses the empty folders, that_shifts_
your data too.

HansH


  Réponse avec citation
Vieux 09/08/2006, 23h50   #4
Leo Andrews
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Yep another mod_rewrite question!

Thanks, all!

HansH wrote:
> "Leo Andrews" <leo@invalid.syntax> schreef in bericht
> news:44d5369d$0$139$7b0f0fd3@reader.news.newnet.co .uk...
>
>>I'm trying to set up a rewrite so that if you have a url along the lines
>>of http://www.mysite.com/features/1/10/ that will redirect to a handler
>>script and pass the 1 and the 10.
>>
>>That was easy and this does it...
>>RewriteRule ^(.*)/(.*)/ /features/feature.php?id=$1&p=$2 [L]
>>
>>Now what if the entered URL is http://www.mysite.com/features/1/10 (note
>>the omission of the trailing slash). That would need to redirect to
>>http://www.mysite.com/features/1/10/ before being handled by the
>>previous rule. However it doesn't work with

>
> Please specify: does nothing, work partial, return error at server or
> browser
>
>>RewriteRule ^(.*)/(.*)$ /features/$1/$2/ [R]

>
> Why telling the _browser_ to retry with trailing slash?
>
>
>>The .htaccess is residing in the features folder and SymLinks is on etc.
>>Can anyone see where I'm going wrong? This should be so easy!

>
> Try
> RewriteRule ^(\d+)/(\d+)/?$ /features/feature.php?id=$1&p=$2 [L]
>
> The trailing slash is optional, adding a ? will allow it to be missing.
> However, good chance mod_dir will kick in before your htaccess is processed.
>
> The \d-s restrict input to numerics only, resulting in a good old 404
> response to 'illegal' values.
> The + makes one digit mandatory, while allowing more. Most probably you'll
> never see zero digits: IIRC apache collapses the empty folders, that_shifts_
> your data too.
>
> HansH
>
>

  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 19h17.


É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,19327 seconds with 12 queries