|
|
|
|
||||||
| comp.info.servers.unix Web servers for UNIX platforms. |
![]() |
|
|
LinkBack | Outils de la discussion |
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
"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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 > > |
|
![]() |
| Outils de la discussion | |
|
|