我使用此htaccess直接访问public/css
,public/js
,public/images
个文件夹,重写从url中移除public:
<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
我想拒绝访问网址http://localhost/public/css/file.css
,但允许http://localhost/css/file.css
,可以这样做吗?
答案 0 :(得分:0)
要解决此问题,您可以将%{THE_REQUEST}
与RewriteCond
一起使用,例如:
RewriteCond "%{THE_REQUEST}" "^GET\s/public/"
如果需要任何方法(GET
,POST
,PUT
等),请重定向,例如:
<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>