- mod_rewrite question
- Posted by Dylan Parry on March 13th, 2006
Pondering the eternal question of "Hobnobs or Rich Tea?", Karl Groves
finally proclaimed:
Hmm... is there any reason why you can't use:
RewriteRule ^article/id/(.+)/?$ /articles/article.php?id=$1
--
Dylan Parry
http://webpageworkshop.co.uk -- FREE Web tutorials and references
Listening to: Pink Floyd - Mother (Live)
- Posted by Justin Koivisto on March 13th, 2006
Dylan Parry wrote:
Actually, it should be "/?$" at the end. To say that the slash is
optional, but it must be the end of the URI.
- Posted by GreyWyvern on March 13th, 2006
And lo, Karl Groves didst speak in alt.www.webmaster:
? alone means "match zero or one of the previous character". It would not
match "article///" :P
The rule above should work. However, since $id comes from the query
string, you will find it in GET, even though the request itself is a
POST. You might want to use PHP's $_REQUEST superglobal instead, which
contains a merging of the POST, GET and COOKIE arrays.
Grey
--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured
spider and site-search engine
- Posted by Karl Groves on March 13th, 2006
Justin Koivisto <justin@koivi.com> wrote in news:K5OdndB5spXT4ojZRVn-
iw@onvoy.com:
Nope! Still not recognizing the POST variable.
See, before it wouldn't recognize it *without* the slash, but with that
method it won't recognize it with the slash.
--
Karl Groves
http://karlcore.com
http://chevelle.karlcore.com
Accessibility Discussion List: http://smallerurl.com/?id=6p764du
- Posted by John Bokma on March 13th, 2006
Karl Groves <karl@NOSPAMkarlcore.com> wrote:
$ means end anchor, so /$ means it *has* to end in a /
--
John Freelance Perl programmer: http://castleamber.com/
Firefox Keywords: http://johnbokma.com/firefox/keymarks-explained.html
- Posted by John Bokma on March 13th, 2006
Justin Koivisto <justin@koivi.com> wrote:
Since .* eats everything (it's greedy), it will eat the / if you make the
/ optional.
Solution:
RewriteRule article/(.*)/([^/]+)/?$ /articles/article.php?$1=$2
(untested) which means / followed by one or more non-slashes, followed by
an optional /
if $1 and $2 are numbers you could do (better):
RewriteRule article/(\d+)/(\d+)/?$ /articles/article.php?$1=$2
Even better (IMO):
RewriteRule article/(\d+)/(\d+)$ http://%{HOST}/article/$1/$2/ [R=301,L]
RewriteRule article/(\d+)/(\d+)/$ /articles/article.php?$1=$2
(untested)
meaning, without a slash, 301 redirect to the slashed version, which is
actually what happens (default?) if you go to http://example.com/foo and
foo is a directory, you're redirected to http://example.com/foo/
--
John Experienced (web) developer: http://castleamber.com/
Firefox RSS: http://johnbokma.com/firefox/rss-and...bookmarks.html
- Posted by John Bokma on March 13th, 2006
GreyWyvern <spam@greywyvern.com> wrote:
but the entire regexp does, which was what Karl was talking about (or at
least how I read it).
--
John Experienced Perl programmer: http://castleamber.com/
Fart Free Fox: http://johnbokma.com/firefox/find-in-page-sound.html
- Posted by GreyWyvern on March 13th, 2006
And lo, John Bokma didst speak in alt.www.webmaster:
Ah yesh. Re-reading the OP, I see Dylan changed the *'s to +'s. My
mistake
Grey
--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured
spider and site-search engine
- Posted by GreyWyvern on March 13th, 2006
And lo, Karl Groves didst speak in alt.www.webmaster:
What POST variable? Rewriting a URI like that to place elements in a
Query String is usually a GET situation.
RewriteRule article/([^/]+)/([^/]+)/?$ /articles/article.php?$1=$2
Give that one a whirl. BTW, do you have any flags at the end of this rule
you haven't told us about?
Grey
--
The technical axiom that nothing is impossible sinisterly implies the
pitfall corollary that nothing is ridiculous.
- http://www.greywyvern.com/orca#search - Orca Search: Full-featured
spider and site-search engine
- Posted by Karl Groves on March 13th, 2006
GreyWyvern <spam@greywyvern.com> wrote in
news
p.s6cvxgjesl6xfd@news.nas.net:
I am using $_REQUEST and it still chokes when using "/?".
--
Karl Groves
http://karlcore.com
http://chevelle.karlcore.com
Accessibility Discussion List: http://smallerurl.com/?id=6p764du


