Question

I'm trying to create a rewrite rule which catches all www.domain.com/dynamicfolder/ (should work both with and without dash) and rewrites it to /index.php?folder=dynamicfolder and also allows for additional parameters.

The thing is, there should be some exceptions, where the rewrite rule shouldn't apply, where the request actually should open/look in a real folder. Some reserved folders, you could call it. Examples of folders where the rule should be ignored: "images", "includes" and "admin".

I have a rewrite rule now, that kind of does the job, but it's only for dynamic folder names with exactly 2 characters. The new rule shouldn't have any limitations, and also - to be demanding, it should be possible to leave out a dynamic folder name, and have the rest of the rewrite url work. :-)

<rule name="Langrewrite" enabled="true">
  <match url="^([a-z]{2,2})/([_0-9a-zA-Z]+)\.html" />
  <conditions logicalGrouping="MatchAll" />
  <action type="Rewrite" url="/index.php?navItem={R:2}&amp;lang={R:1}" />
</rule>
Was it helpful?

Solution

Your question is a bit vague in places, but will try to guess your requirement:

<rule name="DynamicFolder" stopProcessing="true">
    <match url="^(?!(?:images|includes|admin))(.+?)/" />
    <action type="Rewrite" url="/index.php?folder={R:1}" />
</rule>

OTHER TIPS

It might be exactly what Tomek said, but this is how it ended up:

            <rule name="Dynamic Folders" stopProcessing="true">
                <match url="^(?!errorPages/|files/|gfx/)([a-zA-Z-]*)/?([a-zA-Z-]*)/([_0-9a-zA-Z]*)(\.html|\.htm)?" />
                <action type="Rewrite" url="/index.php?var1={R:1}&amp;var2={R:2}&amp;var3={R:3}&amp;var4={R:4}" />
            </rule> 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top