Mod ReWrite -- Allow ReWrite for most pages, disable ReWrite for selected few

On with my Mod ReWrite adventures...

Currently, I have a dynamic page in the root of my directory (shownews.php). Most of the pages in this root level are dynamic, so I have the following rewrite in my .htaccess file:

RewriteRule ^([^/]+)\.html$ /show_news.php?kw=$1 [L]]

So a url like would really display

This works great. The problem is that I also have a contact page and a few other pages that fall victim to my mod rewrite. For example, a link to (which is a real page) would lead to My show news script then fails, because it doesn't recognize the category 'contact.'

So my question is this:
How can I add directives to my .htaccess file that will display actual pages and ignore my shownews ReWrite Rule for specific pages(e.g. Contact, About, etc.).

Any help is appreciated.

Who is Participating?
ramazanyichConnect With a Mentor Commented:
you can use RewriteCond before RewriteRule. For example if you want to exclude /contact.html from processing by rewriterule then you should add following line before RewriteRule directive:
RewriteCond %{REQUEST_URI} !^/contact.html
RewriteRule ...

You can use multiple RewriteCond directives (by default they be concatenated using logical AND but you can say that they can be concatenated using logical OR). For example if you want to disable rewrite rule for /contact.html and /about.html pages then you should use following condition:
RewriteCond %{REQUEST_URI} !^/contact.html [OR]
RewriteCond %{REQUEST_URI} !^/about.html
RewriteRule ...

or you can make complex regular expression in one RewriteCond directive:
RewriteCond %{REQUEST_URI} !^/[contact|about].html
RewriteRule ...
cjasonAuthor Commented:
Hi ramazanyich-

I tried your suggestion, but no avail. I think I might be misunderstanding where that Rewrite condition needs to go.

Here's my current .htaccess file:

Options -indexes

<Files .htaccess>
order allow,deny
deny from all

RewriteEngine on

# Block this IP
RewriteCond %{REMOTE_ADDR} ^69\.95\.42\.202$
RewriteCond %{REQUEST_URI} !^/errordocs/error\.html$ [NC]
RewriteRule ^(.*) /errordocs/error.html [R]

# This is the key script of the site
RewriteRule ^([^/]+)\.html$ /show_news.php?kw=$1 [L]]

So as you can see, there is another RewriteCond thrown in there that I forgot to mention. When I tried your suggestion, I was getting internal server errors. Any ideas?
cjasonAuthor Commented:
ramazanyich -

Got it working. There was something wrong with one of my own ReWrite statements. Your adivce was perfect. Thanks!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.