R – Having problems with a Rewrite rule

mod-rewriteredirect

I have an application most of it is still in development that's why i need to block access on all pages but just not two of them.

Suppose i have a.php all requests will be redirected to here except b.php.

So i think there should be 3 rules:

1st: when a.php and b.php are requested they should be visible to user,

2nd: if anything other than those two is requested, 
     it should be redirected to a.php.

3rd: for external css,javascript and image files 
     there should be an access rule

Since i dont have much experience with server administration, i believe i'm totally lost:)

This is what i tried:

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !^/b.php
RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ a.php

Best Solution

In practice you would swap the second and third rule as your second rule would be the default route:

# 1st
RewriteRule ^(a\.php|b\.php)$ - [L]

# 3rd
RewriteRule \.(js|ico|txt|gif|jpg|png|css)$ - [L]

# 2nd
RewriteRule !^a\.php$ a.php [L]

The subsitution - means that the URI is not changed.

Related Question