zlog
zlog

Reputation: 3316

mod_rewrite rule for all except some specific paths

How do I write a mod_rewrite rule that is the opposite of this:

RewriteRule ^(.+)/fixed_path/(page1|page2)([^/]+)$ /index.php?fixed_path/show/$2 [L]

That is, I want all pages in the form:

ignored_path/fixed_path/x

to redirect to

/index.php/fixed_path/show/x

where

ie, I want a rule to redirect everything in the form "ignored_path/fixed_path/x", except specific pages (page1, page2, etc.), which are handled properly by my web app already.

I'm trying to use ! and [^] syntax, but I don't quite understand how these work, especially when they involve words not single characters.

Upvotes: 0

Views: 266

Answers (1)

ridgerunner
ridgerunner

Reputation: 34395

Assuming you want blah/path/some_param (but not the two special cases: blah/path/page1 and blah/path/page2), to be redirected to /path/show/some_param, which is then rewritten to index.php?var=/path/show/some_param (so that the browser shows /path/show/some_param in the address bar), then the following should do the trick:

# Check if we have the mod_rewrite module available...
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^path/(?!page1$|page2$)([^/]+)$  http://yourdomain.com/path/show/$1 [R]
    RewriteRule ^(path/show/.*)$  index.php?var=$1 [L]
</IfModule>

Upvotes: 1

Related Questions