mod rewrite friendly urls problem

Discuss practical ways rearrange URLs using mod_rewrite.

mod rewrite friendly urls problem

Postby bender » Tue Oct 14, 2008 4:33 am

Code: Select all
ErrorDocument 404 /404index.php


RewriteBase /

RewriteEngine on

RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)-keyword-([0-9]+)\.html$ index.php?page=browse&category=$2 [L]

RewriteRule ^([-_!~*'()$a-zA-Z0-9]+)-([0-9]+)([$a-zA-Z0-9]+)\.html$ ?page=detail&get_id=$2&category=$2 [L]




Code: Select all
http://example.com/?page=detail&get_id=22&category=33


I've read so much information and still can not find a solution. I am using mod rewrite to change my urls. The above is what I am using currently. I am reffering to the second rule. It works fine unless the long url has double(or triple) digits in the &category. The &get_id is fine at double digits. The error is that it redirects to a blank page.

How do I account for the double digits in the .htaccess?

Thanks in advance,
B
bender
 
Posts: 13
Joined: Sat Aug 09, 2008 9:23 pm

Postby richardk » Tue Oct 14, 2008 9:56 am

Try replacing
Code: Select all
[$a-zA-Z0-9]+

with
Code: Select all
[$a-zA-Z][$a-zA-Z0-9]*


Code: Select all
ErrorDocument 404 /404index.php
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^([-_!~*'\(\)\$a-zA-Z0-9]+)-keyword-([0-9]+)\.html$ /index.php?page=browse&category=$2 [L]

RewriteRule ^([-_!~*'\(\)\$a-zA-Z0-9]+)-([0-9]+)([$a-zA-Z][$a-zA-Z0-9]*)\.html$ /index.php?page=detail&get_id=$2&category=$2 [L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: No registered users and 8 guests

cron