PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > php.general > RewriteRule
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
RewriteRule

Réponse
 
LinkBack Outils de la discussion
Vieux 12/10/2008, 18h57   #1
Ron Piggott
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut RewriteRule

I am needing to pass 2 variables in a script I am writing. Does anyone
know how to do this?

http://www.domain.com/blog/1/2/

I know how to pass 1; I have no idea how to write a rewrite rule to pass
the 2 as well.

Thanks,

Ron

  Réponse avec citation
Vieux 12/10/2008, 20h11   #2
Daniel Brown
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] RewriteRule

On Sun, Oct 12, 2008 at 12:57 PM, Ron Piggott
<ron.php@actsministries.org> wrote:
> I am needing to pass 2 variables in a script I am writing. Does anyone
> know how to do this?
>
> http://www.domain.com/blog/1/2/
>
> I know how to pass 1; I have no idea how to write a rewrite rule to pass
> the 2 as well.


That's an Apache question, Ron, but it's a matter of using
RewriteRule to parse $1 and $2 (and so forth).

--
</Daniel P. Brown>
More full-root dedicated server packages:
Intel 2.4GHz/60GB/512MB/2TB $49.99/mo.
Intel 3.06GHz/80GB/1GB/2TB $59.99/mo.
Intel 2.4GHz/320/GB/1GB/3TB $74.99/mo.
Dedicated servers, VPS, and hosting from $2.50/mo.
  Réponse avec citation
Vieux 12/10/2008, 20h40   #3
Yeti
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] RewriteRule

#.htaccess

RewriteEngine on
RewriteBase /

#Apache recurses into htaccess 3 times so we have to make sure not to
overwrite an already processed rule
RewriteCond %{REQUEST_URI} !^.*(\.php|\.css|\.js|\.html|\.ico|robots\.txt).*$
#The rewrite condition below can be used to pass through GET
parameters (direct access)
#RewriteCond %{THE_REQUEST} !^.*\?getparam1=.*$
# /blog/*/**/*** -----> blog.php?getparam1=*&getparam2=**
#RewriteRule /blog[/]{0,}([a-zA-Z0-9 ]{1,})[/]{0,}([a-zA-Z0-9
]{1,})[/]{0,}[.*]{0,}$ blog.php?getparam1=$1&getparam2=$2
RewriteRule ^blog[/]{0,}([^/]{0,})[/]{0,}([^/]{0,})[/]{0,}.*$
blog.php?getparam1=$1&getparam2=$2 [NC,QSA,L]

# All not found requests --> somefile.php
ErrorDocument 404 /somefile.php
  Réponse avec citation
Vieux 13/10/2008, 08h42   #4
Per Jessen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] RewriteRule

Yeti wrote:

> RewriteRule ^blog[/]{0,}([^/]{0,})[/]{0,}([^/]{0,})[/]{0,}.*$
> blog.php?getparam1=$1&getparam2=$2 [NC,QSA,L]


What's the point of using '{0,}' instead '*' ?

I think I would have written something like this:

# http://www.domain.com/blog/1/2/
RewriteRule ^blog/([^/]+)/([^/]+)/ blog.php?getparam1=$1&getparam2=$2
[NC,QSA,L]


/Per Jessen, Zürich

  Réponse avec citation
Vieux 13/10/2008, 14h46   #5
Yeti
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] RewriteRule

> What's the point of using '{0,}' instead '*' ?

Well the thing is that with the {0,} more REQUEST_URIs are valid:
eg.
/blog
/blog/
/blog/17
/blog/17/
/blog/17/0
/blog/17/0/

AND additional characters get ignored (like when it is necessary to
reload content with javascript, due to caching issues)

/blog/17/0/ignored_string
  Réponse avec citation
Vieux 13/10/2008, 14h50   #6
Yeti
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] RewriteRule

>Jessen wrote:
>RewriteRule ^blog/([^/]+)/([^/]+)/ blog.php?getparam1=$1&getparam2=$2 [NC,QSA,L]


Of course, your truely does what the OP asked for + it cuts of all
strings after the last /

/A yeti
  Réponse avec citation
Vieux 13/10/2008, 14h59   #7
Per Jessen
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] RewriteRule

Yeti wrote:

>> What's the point of using '{0,}' instead '*' ?

>
> Well the thing is that with the {0,} more REQUEST_URIs are valid:
> eg.
> /blog
> /blog/
> /blog/17
> /blog/17/
> /blog/17/0
> /blog/17/0/


Yeti,

I must be slow today - I still can't see the difference between

'{0,}' (= 0 or more instances of the previous)

and

'*' (= 0, 1 or more instances of the previous)



/Per Jessen, Zürich

  Réponse avec citation
Vieux 13/10/2008, 15h20   #8
Yeti
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: [PHP] RewriteRule

You are absoloodle right about that. Although I'm not sure about their
greediness, which might be different.
I prefer the '{0,}' in my rewrite rules because I usually define the
max-length to prevent code injection.

eg.

# to make sure only the first 8 chars get passed on to PHP
RewriteRule ^blog/([^/]{0,8} index.php?a=$1 [NC,QSA,L]

So that's why they ended up in my reply.
  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 17h09.


É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,13813 seconds with 16 queries