Forum Moderators: phranque

Message Too Old, No Replies

Assistance with mod_rewrite

crashed site needs help!

         

DavidA

2:51 am on Apr 20, 2005 (gmt 0)

10+ Year Member



Think I may have it. :)

[edited by: DavidA at 3:22 am (utc) on April 20, 2005]

jdMorgan

3:22 am on Apr 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



DavidA,

Welcome to WebmasterWorld!

It looks to me as if you are generating the static links inconsistently; Some have trailing slashes, and some don't. Similarly, some of the rewriterules you posted require a trailing slash, and some won't accept one.

That's the first place I'd look -- be consistent with the trailing slashes.

I'd also recommend adding an [L] flag to each rewriterule. This won't fix your problem, just make your site a bit faster, since it tells mod_rewrite to quit once a match is found and the URL is rewritten.

In the rewriterules, you can make the trailing slash optional be using the "/?$" construct at the end of each pattern. However, your link generation should still be consistent.

Jim

jd01

3:24 am on Apr 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The problem looks like it is the regular expression at the end of the rewrite and if you used a regular expression in the middle you could cut it down to three:

I would recommend changing it to:

# Return alphabetical pattern only (trailing/optional)
RewriteRule ^([a-z_-]+)/?$ /template.php?country=$1 [NC,L]

#Return alphabetical pattern/number/ (trailing/optional)
RewriteRule ^([a-z_-]+)/([0-9]+)/?$ /template.php?country=$1&page=$2 [NC,L]

#Return alphabetical pattern/alphabetical pattern/number/ (/number/ string optional)
RewriteRule ^([a-z_-]+)/([a-z_-]+)/?([0-9]+)?$ /template.php?country=$1&$2=$3 [NC,L]

NC designates No Case, should increase processing speed.
L designates last, quits processing all rules as soon as last is seen.

/template.php? needs to be the full path to the file EG if the template.php file is in the directory stuff the path needs to be changed to:
/stuff/template.php?

This should help you out.

Justin