Welcome to WebmasterWorld Guest from 54.161.181.156

Forum Moderators: Ocean10000 & incrediBILL & phranque

Using one rewritecond on several rewrite rules

   
10:16 am on Aug 14, 2007 (gmt 0)

5+ Year Member



Hi,

I have these rules and am going to have to create many more if I cant find an alternative.

I am trying to match every permutation/combination of "folder1", "folder2" and "folder3"

RewriteRule ^/?([-a-zA-Z0-9_\-]+)/([-a-zA-Z0-9_\-]+)/folder1-([a-zA-Z0-9_\-]+)/folder2-([a-zA-Z0-9_\-]+)/folder3-([-a-zA-Z0-9_\-]+)/?$
index.php?url1=$1&url2=$2&folder1=$3&folder2=$4&folder3=$5 [NC]

RewriteRule ^/?([-a-zA-Z0-9_\-]+)/([-a-zA-Z0-9_\-]+)/folder2-([a-zA-Z0-9_\-]+)/folder1-([a-zA-Z0-9_\-]+)/folder3-([-a-zA-Z0-9_\-]+)/?$
index.php?url1=$1&url2=$2&folder2=$3&folder1=$4&folder3=$5 [NC]

RewriteRule ^/?([-a-zA-Z0-9_\-]+)/([-a-zA-Z0-9_\-]+)/folder3-([-a-zA-Z0-9_\-]+)/folder2-([a-zA-Z0-9_\-]+)/folder1-([a-zA-Z0-9_\-]+)/?$
index.php?url1=$1&url2=$2&folder3=$3&folder2=$4&folder1=$5 [NC]

I am using my application to detect the word "folder(x)-" in the URL and then serve the appropriate content.

Is there any way that these rules can be combined into several rewrite conditions?

I am a bit daunted by the fact that I have more "folders" and could perhaps have thousands of combinations and therefore would have to write thousands of rewrite rules to match them.

Thanks in advance for any guidance

[edited by: Zacharias at 10:26 am (utc) on Aug. 14, 2007]

6:53 pm on Aug 14, 2007 (gmt 0)

WebmasterWorld Senior Member jdmorgan is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Consider this:

How about using a single rule to match *any* of URLs in the format you've shown, and rewrite all of them to your script. You can then modify the script to check the 'validity' of each "folder" value against your database, handle the request if it's valid, or return an error status if not.

In other words, move the heavy lifting into the script, where you have better equipment readily available to handle all the contingencies.

Jim

2:40 am on Aug 15, 2007 (gmt 0)

5+ Year Member



Thanks for the advice, it really helped :)
 

Featured Threads

Hot Threads This Week

Hot Threads This Month