0

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
1
  • As for "most of it is still in development": are you sure you don't actually want something that requests for authentication if any file other than a.php or b.php is requested?
    – Arjan
    Sep 7, 2009 at 18:16

2 Answers 2

2

I'm not completely sure what "there should an access rule" means for point 3 so I'm taking it as "permit access to files with these extensions".

I think this does what you're asking for but that might not be what you want -- you're effectively going to stop anything besides JS/CSS/etc, a.php and b.php from being reachable, which is probably not much use.

# permit JS, CSS, etc
# - means don't rewrite the URL
# [L] means stop processing rules
RewriteRule \.(js|ico|txt|gif|jpg|png|css)$ - [L]

# Permit a.php and b.php
RewriteRule ^/[ab]\.php$ - [L]

# HTTP 302 redirect anything else to a.php
RewriteRule ^ http://your.server/a.php [R]
1
  • Or, for the last line, to NOT change the URL in the browser: RewriteRule . a.php
    – Arjan
    Sep 8, 2009 at 7:36
1

Well, for one thing, you need to add a.php to the RewriteCond (a|b).php or else you've created an endless loop where a.php is always redirected to itself.

1
  • I'm also not sure if you need the slash in the RewriteCond if you're using RewriteBase. Try it both ways. Sep 7, 2009 at 18:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .