|
|
|
#1 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#2 |
|
Messages: n/a
Hébergeur: |
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. |
|
|
|
#3 |
|
Messages: n/a
Hébergeur: |
#.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 |
|
|
|
#4 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#5 |
|
Messages: n/a
Hébergeur: |
> 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 |
|
|
|
#6 |
|
Messages: n/a
Hébergeur: |
>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 |
|
|
|
#7 |
|
Messages: n/a
Hébergeur: |
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 |
|
|
|
#8 |
|
Messages: n/a
Hébergeur: |
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. |
|
![]() |
| Outils de la discussion | |
|
|