2014-05-12 175 views
0

我有一個或多個文件,在我的服務器上,我想暫時或永久地隱藏用戶和搜索引擎,使用.htaccess將這些頁面重定向到404頁面。這意味着任何嘗試查看頁面的用戶或搜索引擎機器人都會看到一個404頁面。.htaccess隱藏頁面404頁面

這裏是我加入到我的.htaccess文件的一些文件重定向到404頁的行,但它似乎並沒有工作:

RedirectMatch 404 antalya_apartment.php?bid=2&page=236 
RedirectMatch 404 antalya_apartment.php?bid=3&page=129 

這裏是.htaccess代碼:

Options +FollowSymLinks +Indexes +MultiViews 

RewriteCond %{QUERY_STRING} (^|&)bid=2(&|$) 
RewriteCond %{QUERY_STRING} (^|&)page=236(&|$) 
RewriteCond %{QUERY_STRING} (^|&)bid=3(&|$) 
RewriteCond %{QUERY_STRING} (^|&)page=129(&|$) 
RewriteRule ^/antalya_apartment.php?$ http://turkish-property-world.com/ [L,R=404] 
+0

那麼當你去' /antalya_apartment.php?bid = 3&page = 129'時會發生什麼? – ChrisW

+0

可能重複[如何重定向基於查詢字符串的URL?](http://stackoverflow.com/questions/13073253/how-to-redirect-urls-based-on-query-string) – JakeGould

+0

奇怪的或與頁面仍然顯示,並且我得到一個HTTP響應頭狀態:HTTP/1.1 200 OK。所有我的其他htaccess RewriteRule工作正常。 – antalya

回答

1

由於URL中的查詢字符串,簡單的RedirectMatch將不起作用。試試這個,而不是使用RewriteRuleRewriteCond

RewriteEngine On 
RewriteCond %{QUERY_STRING} (^|&)bid=2(&|$) 
RewriteCond %{QUERY_STRING} (^|&)page=236(&|$) 
RewriteCond %{QUERY_STRING} (^|&)bid=3(&|$) 
RewriteCond %{QUERY_STRING} (^|&)page=129(&|$) 
RewriteRule ^/antalya_apartment.php?$ http://your.sites.domain.name.here/ [L,R=404] 

注意我設置的http://your.sites.domain.name.here/的目的地,因爲,據我所知,你真的不能沒有重定向目標。但是,如果有辦法讓它變成毫無意義的東西 - 或者默認的404 - 沒有指出我想知道的目的地。

編輯:此外,你的Apache甚至解析.htaccess規則呢? AllowOveride設爲All?有關更多詳細信息,請參閱the official Apache documentation

+0

'(^ |&)bid = [23](&| $)'也會幫助:) – hjpotter92

+0

這個。是我正在尋找的那種規則......但卻無法讓它起作用。我有一個RewriteCond非www重定向到RewriteRule www並且正在工作。即使我寫了http://你的網站。作爲http:// www,認爲它可能衝突似乎不是問題。 – antalya

+0

我希望能夠獲得美妙的代碼,但沒有。我很快試圖檢查爲什麼,如果與我的.htaccess規則有關,但沒有任何內容。即使是暫時的我也不知道www到www規則並且沒有運氣。我將ErrorDocument 404 /index.php更改回404.shtml,但仍然沒有去。 – antalya