rodenbushdesign
rodenbushdesign

Reputation: 81

.htaccess mod_rewrite for nested folder structuring

I recently found an article online that told me about this:

RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2 [NC]

Only thing that is driving me crazy right now is if I want to be able to have the 2nd directory or not. Like:

RewriteRule ^mock-up/([^/]+)/([^/]+) /mock-up/index.php?page=$1&section=$2 [NC]
RewriteRule ^mock-up/([^/]+) /mock-up/index.php?page=$1 [NC]

But that's breaking apache... so what to do? Please help, I need to seo for my client and I would prefer not to have to make individual files for this.

Upvotes: 0

Views: 2038

Answers (1)

Gumbo
Gumbo

Reputation: 655239

The problem is that mock-up/index.php is also matched by mock-up/([^/]+). So you need to exclude the target, either directly:

RewriteRule ^mock-up/index\.php$ - [L]

Or indirectly:

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

So try this:

RewriteRule ^mock-up/index\.php$ - [L]
RewriteRule ^mock-up/([^/]+)/([^/]+)$ /mock-up/index.php?page=$1&section=$2 [NC]
RewriteRule ^mock-up/([^/]+)$ /mock-up/index.php?page=$1 [NC]

Upvotes: 1

Related Questions