2016-05-20 51 views
4

我想拒绝访问以/mapname开头的网址,以便像/mapname/mapname2/mapname/file1等网址被阻止。但有一个我想要允许的url,例如/mapname/mapname.php/something/something/something.php/something。我如何使用htaccess来做到这一点?htaccess拒绝访问特定网址,但有1个例外

拒绝访问我使用了下面的代码示例。这工作,但我无法弄清楚如何允许特定的网址。

RewriteCond %{REQUEST_URI} /mapname 
RewriteRule ^.*$/[R=301,L] 

回答

1

在单RewriteRule人能做到这一点使用负前瞻:

RewriteRule ^mapname(?!/something\.php/allow/this/uri/?$) - [F,L,NC] 
+1

谢谢,这个作品! – Femke

1

您可以使用此:

RewriteRule ^mapname/something\.php/allow/this/uri/?$ - [L] 
#Deny any other uri string starting with "/mapname 
RewriteCond %{REQUEST_URI} ^/mapname 
RewriteRule ^.*$ - [F,L] 
+1

谢谢,这个作品!我选择其他答案是正确的,因为它更紧凑:) – Femke

相关问题