2016-06-28 59 views
0

我顯示404錯誤信息顯示404錯誤,如果用戶試圖訪問特定文件夾struture在訪問特定的文件夾結構

RewriteCond %{REQUEST_URI} ^/protected$ 
RewriteRule .* /404.cfm [NC,L] 

RewriteCond %{REQUEST_URI} ^/protected/pdf$ 
RewriteRule .* /404.cfm [NC,L] 

有什麼辦法既

/protected/pdf and /protected 
結合

在一種情況下,並在結束時正斜槓作爲可選

我試圖讓最後一個正斜槓可選,如

RewriteCond %{REQUEST_URI} ^/protected/?$ 

但它不工作。

回答

1

嘗試:

RewriteCond %{REQUEST_URI} ^/(protected|protected/pdf)/?$ 
RewriteRule .* /404.cfm [NC,L] 

您也可以使用帶有標誌條件或

RewriteCond %{REQUEST_URI} ^/protected/?$ [OR] 
RewriteCond %{REQUEST_URI} ^/protected/pdf/?$ 
RewriteRule .* /404.cfm [NC,L] 
0

它不匹配:

RewriteCond %{REQUEST_URI} ^/protected/?$ 

意味着匹配以/與保護開始一切可選/和結束。 我想要匹配它,你必須刪除$。

RewriteCond %{REQUEST_URI} ^/protected/?.*$ 

或:

RewriteCond %{REQUEST_URI} ^/protected 

或者你可以留限制性的@starkeen提供的解決方案,它取決於你的需求。