2015-05-18 41 views
0

我使用这个htaccess的访问public/csspublic/jspublic/images文件夹直接,它重写通过网址删除公众拒绝公用文件夹的直接访问:重定向或

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteBase/
    RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [QSA,L] 
</IfModule> 

EG。当访问该网址http://localhost/css/file.css显示http://localhost/public/css/file.css

我想拒绝访问的URL http://localhost/public/css/file.css但允许http://localhost/css/file.css,就可以做到这一点?

+0

我可以问为什么这很重要?无论哪种方式,你仍然可以访问css文件。无论如何,这在源头上。所有的资产都将提供给客户。 –

+0

@PanamaJack感谢您的关注,没有特别的理由,这将是一个“规范URL”的问题。 –

+0

我在想的问题是,用户永远不会看到网址,并且可以使用robots.txt来防止抓取该文件夹,但是我只是没有看到资产文件夹上必须可用于页面的点正确显示。 –

回答

0

对于解决您可以使用%{THE_REQUEST}RewriteCond的问题,例如:

RewriteCond "%{THE_REQUEST}" "^GET\s/public/" 

如果需要的任何方法(GETPOSTPUT等),重定向例如:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteBase/

    RewriteCond "%{THE_REQUEST}" "^[A-Z]+\s/public/" 
    RewriteRule ^public/(.*)$ other-directory/$0 [QSA,L] 

    RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [QSA,L] 
</IfModule> 

拒绝访问例如:

<IfModule mod_rewrite.c> 
    RewriteEngine On 

    RewriteBase/

    RewriteCond "%{THE_REQUEST}" "^[A-Z]+\s/public/" 
    RewriteRule ^public/(.*)$ fake-directory/$0 [F] 

    RewriteRule ^(css|js|images)/(.*)$ public/$1/$2 [QSA,L] 
</IfModule>