我有一个应用程序大部分仍在开发中,这就是为什么我需要阻止所有页面上的访问,但不是其中的两个。
假设我有一个.php所有的请求将被redirect到这里,除了b.php。
所以我认为应该有3条规则:
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
由于我没有太多的服务器pipe理经验,我相信我完全失去了:)
这是我试过的:
RewriteBase / RewriteCond %{REQUEST_FILENAME} !^/b.php RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ a.php
我不完全确定“应该有一个访问规则”是指第3点,所以我把它作为“允许访问带有这些扩展名的文件”。
我认为这是做你所要求的,但这可能不是你想要的 – 你实际上将阻止任何除了JS / CSS /等,a.php和b.php从可达,这可能不是很多使用。
# 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]
那么,一方面,你需要添加a.php到RewriteCond(a | b).php,否则你创build了一个无限循环,其中a.php总是被redirect到自己。