如何限制目录访问

时间:2016-07-12 16:19:04

标签: .htaccess url-redirection

我有文件夹目录http://test.com/app/cl/login.php。如果有人试图访问应用程序文件夹,它可以。如果有人试图直接访问app文件夹,请告诉我如何阻止他们访问它并将网址重定向到http://test.com/。我尝试通过htaccess来实现,但它会阻止整个网站

我尝试的选项

  RewriteEngine On
  RewriteRule ^app/ - [L,R=404] 

  RewriteEngine on 
  RewriteCond %{HTTP_HOST} ^test\.com\/app [NC,OR]
  RewriteRule ^(.*)$ http:\/\/test\.com\/$1 [L,R=301,NC] 

  Redirect 301 /app test.com

1 个答案:

答案 0 :(得分:0)

您可以使用以下规则:

  RewriteEngine On
  #1) redirect "/app/"
  RewriteRule ^app/?$ http://example.com/ [L,R]
  #2) redirect "/app/cl/"
  RewriteRule ^app/cl/?$ http://example.com/ [L,R]

您也可以使用RedirectMatch指令完成此操作:

RedirectMatch ^/app/?$ http://example.com/
RedirectMatch ^/app/cl/?$ http://example.com/