Welcome to WebmasterWorld Guest from 54.159.50.111

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Using one rewritecond on several rewrite rules

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

New User

10+ Year Member

joined:Dec 5, 2005
posts:31
votes: 0


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)

Senior Member

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

joined:Mar 31, 2002
posts:25430
votes: 0


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)

New User

10+ Year Member

joined:Dec 5, 2005
posts:31
votes: 0


Thanks for the advice, it really helped :)