[thelist] rewrite rule

Phil Turmel philip at turmel.org
Fri Apr 15 09:13:20 CDT 2005


Dan:

You could simply roll the trailing / check into the original rule, 
avoiding redirection entirely:

RewriteRule ^/category/([0-9]+)/([0-9]+)/?$ \
   /category.jsp?catid=$1&type=$2 [L,PT]
RewriteRule ^/subcategory/([0-9]+)/([0-9]+)/([0-9]+)/?$ \
   /subcategory.jsp?catid=$1&type=$2&style=$3 [L,PT]
RewriteRule ^/product/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/?$ \
   /product.jsp?catid=$1&type=$2&style=$3&prodid=$4 [L,PT]

(Note the extra ? after the trailing slash)

This does leave the unslashed version in the browser address bar, if 
that matters to you.

Phil

Dan McCullough wrote:
> I have some rewrite rules that work pretty well.  However in case
> someone inadvertanly drops the last slash I need to have a rule to add
> the slash to the end of its missing.
> 
> current:
> RewriteRule ^/category/([0-9]+)/([0-9]+)/$ /category.jsp?catid=$1&type=$2 [L,PT]
> RewriteRule ^/subcategory/([0-9]+)/([0-9]+)/([0-9]+)/$
> /subcategory.jsp?catid=$1&type=$2&style=$3 [L,PT]
> RewriteRule ^/product/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/$
> /product.jsp?catid=$1&type=$2&style=$3&prodid=$4 [L,PT]
> 
> adding:
> RewriteRule ^/category/([0-9]+)/([0-9]+)$ /category/$1/$2/ [R] 
> RewriteRule ^/subcategory/([0-9]+)/([0-9]+)/([0-9]+)$ /subcategory/$1/$2/$3/ [R]
> RewriteRule ^/product/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)$
> /product/$1/$2/$3/$4/ [R]
> 
> there seems to be a problem with the new rules.  any thoughts?



More information about the thelist mailing list