[vox-tech] Question related to Apache mod_rewrite and regular expressions

Harold Lee harold3 at gmail.com
Mon Apr 20 20:56:54 PDT 2009


On Mon, Apr 20, 2009 at 3:36 PM, David Spencer <spencer at pageweavers.com>wrote:

> I've killed the better part of the morning and this afternon trying to
> figure out this use of Apache's mod_rewrite.


Welcome to mod_rewrite. There's a logging facility that can create a log of
which rules were tried, but it doesn't help in this case where you only have
one rule.


> RewriteEngine On
> RewriteRule ^/?product-([A-Za-z0-9-]+)\.php$ product.php?name=$1
> [ R=301,L]
>

You did a gread job here, but ...

1) No spaces in the [] at the end of the line, so you want [R=301,L]

2) I found I needed to add this option also:
Options +SymLinksIfOwnerMatch

3) You almost certainly also want QSA (query string append), making it
[R=301,L,QSA] at the end of the line. This will add the name parameter to
whatever other parameters were sent, instead of dropping the original
parameters:

    product-a.php?quantity=4 -> product.php?name=a&quantity=4

You can check Apache's error_log if this still isn't working for hints.

Harold
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.lugod.org/pipermail/vox-tech/attachments/20090420/cd9ace2a/attachment.htm 


More information about the vox-tech mailing list