Search Engine Optimization > Webmaster World > mod_rewrite question
mod_rewrite question
Posted by Karl Groves on March 13th, 2006

John Bokma <john@castleamber.com> wrote in
news:Xns9785595DE6623castleamber@130.133.1.4:

That did it.
I was stupidly replacing "$" with "?" and never thought to combine them.


--
Karl Groves
http://karlcore.com
http://chevelle.karlcore.com

Accessibility Discussion List: http://smallerurl.com/?id=6p764du

Posted by Justin Koivisto on March 13th, 2006

John Bokma wrote:
I tend not to use .* at all in my rewrite rules for that reason. I can't
believe that I didn't see that when I posted. :\

For some reason, that looks a bit odd... Possibly because of the $1=$2
part. I'd be more inclined to see something like:

RewriteRule article/(\d+)/?$ /articles/article.php?id=$1

Of course, I'd usually date the articles, so would use something more like:

RewriteRule ^article(/(\d{4})(/(\d{2})(/(\d{2})(/(\d+))?)?)?)?/?$
/articles.php?year=$2&month=$4&day=$6&id=$8

Then in the articles.php script, $_GET would have the following
structure (always):

Array(
[year] =>
[month] =>
[day] =>
[id] =>
)

Then you simply check if a key is !empty() to know if that was part of
the URI.

I like this too.

Posted by Dylan Parry on March 13th, 2006

Pondering the eternal question of "Hobnobs or Rich Tea?", GreyWyvern
finally proclaimed:

Yeah, sorry, I didn't make myself entirely clear. I changed the *'s to
+'s to *stop* it matching "article///", which it would have done had I
not noticed and changed it

--
Dylan Parry
http://electricfreedom.org -- Where the Music Progressively Rocks!

Listening to: Godspeed You! Black Emperor - Storm

Posted by John Bokma on March 13th, 2006

Justin Koivisto <justin@koivi.com> wrote:

....

I read it as article/1/10 (article 1, page 10, or section 10)

Yup, I too prefer to make the regexp as specific as possible. Otherwise
one might end up with several URLs all going to the same page (which is a
problem when internally redirecting).

I would love to see PCRE in Apache, no idea if this is planned, or in 2.x


--
John

Net::Google and Perl: http://johnbokma.com/perl/net-google.html

Posted by Justin Koivisto on March 13th, 2006

John Bokma wrote:
3 words: negative look ahead

Posted by T Wake on March 13th, 2006

On Monday 13 March 2006 13:42, hug (contact_info@sig_line.clickit)
procrastinated for a bit then wrote in alt.www.webmaster
(<uita12d60u20kbuvogqk53phsoqlrhddna@4ax.com>):

You have no idea how much I agree with you here! Even after years, regular
expressions make my eyes water and it takes me hours to work even the
simplest ones out.

I cant tell you how envious I am of the people who seem to be able to
"think" in them. *bah*

--
T Wake

Posted by hug on March 13th, 2006

T Wake <taswakeAT@hotmail.com> wrote:

Karl seems able to "think" them yet he needed to seek help to solve
the problem. I realize there are performance advantages to the
magical things one can do via htaccess, but I tend to choose things I
can be certain will work. Mileage varies.

--
http://www.ren-prod-inc.com/hug_soft...action=contact

Funbolt.com - Entertainment portal, wallpapers, sexy celebs