RewriteRule Help

Discuss practical ways rearrange URLs using mod_rewrite.

RewriteRule Help

Postby MrD3SAi » Tue Jun 24, 2008 5:55 pm

I currently have /dir/filename.php that takes these query string:
Code: Select all
/dir/filename.php
/dir/filename.php?do=add
/dir/filename.php?do=edit&id=1
/dir/filaname.php?do=delete&id=1

I currently have the following rule:
Code: Select all
RewriteRule ^dir/filename/([A-Za-z0-9_-]+)/(.*)/?$ /dir/filename.php?do=$1&id=$2 [L]

It works for all the above except if I got to:
Code: Select all
/dir/filename/

I get a 404 Not Found error.

Thanks again in advance!
MrD3SAi
 
Posts: 1
Joined: Tue Jun 24, 2008 5:50 pm

Postby richardk » Thu Jun 26, 2008 1:00 pm

Code: Select all
/([A-Za-z0-9_-]+)

isn't optional.

You could do it with two rules, or
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^dir/filename(?:/([-a-zA-Z0-9_]+)(?:/([0-9]+))?)?/?$ /dir/filename.php?do=$1&id=$2 [QSA,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 38 guests

cron