Help optimazing my rewrite rules

Discuss practical ways rearrange URLs using mod_rewrite.

Help optimazing my rewrite rules

Postby Stazh » Sun Jan 31, 2010 12:42 pm

Hi there,

i'm new to mod_rewrite and need help optimizing (if possible) my rewrite rules.

I'm currently using this rules for my web page (in .htaccess file):
Code: Select all
RewriteEngine on

RewriteRule ^([a-zA-Z0-9\-]+)$ index.php?Arg1=$1 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/$ index.php?Arg1=$1 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)$ index.php?Arg1=$1&Arg2=$2 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ index.php?Arg1=$1&Arg2=$2 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)$ index.php?Arg1=$1&Arg2=$2&Arg3=$3 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ index.php?Arg1=$1&Arg2=$2&Arg3=$3 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)$ index.php?Arg1=$1&Arg2=$2&Arg3=$3&Arg4=$4 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ index.php?Arg1=$1&Arg2=$2&Arg3=$3&Arg4=$4 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)$ index.php?Arg1=$1&Arg2=$2&Arg3=$3&Arg4=$4&Arg5=$5 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ index.php?Arg1=$1&Arg2=$2&Arg3=$3&Arg4=$4&Arg5=$5 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)$ index.php?Arg1=$1&Arg2=$2&Arg3=$3&Arg4=$4&Arg5=$5&Arg6=$6 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ index.php?Arg1=$1&Arg2=$2&Arg3=$3&Arg4=$4&Arg5=$5&Arg6=$6 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)$ index.php?Arg1=$1&Arg2=$2&Arg3=$3&Arg4=$4&Arg5=$5&Arg6=$6&Arg7=$7 [PT]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/$ index.php?Arg1=$1&Arg2=$2&Arg3=$3&Arg4=$4&Arg5=$5&Arg6=$6&Arg7=$7 [PT]


In short, anything after my domain gets transformed to index.php?Arg1=...&Arg2=... and so on depending on the number of the "directory" requests.

I'm wondering is there any way to simplify those rules. It works great for me, but it's ugly and probably demanding on mod_rewrite.
Stazh
 
Posts: 1
Joined: Sun Jan 31, 2010 12:35 pm

Return to Friendly URLs with Mod_Rewrite

Who is online

Users browsing this forum: Google [Bot] and 1 guest

cron