簡體   English   中英

兩個正則表達式重寫規則來重定向 404 url

[英]Two regex rewrite rules to redirect 404 urls

我有以下兩個 url,它們給了我一些令人討厭的 404 錯誤,我想通過向 apache 添加一些重寫規則來修復這些錯誤,我必須認識到我對正則表達式的理解不足以編寫正確的規則。

第一URL

http://www.example.com/fincas-rusticas/finca-rustica_en_alacant-alicante/lalacanti/alicante/function.strtotime

必須重定向到相同的 url 最后沒有 /function.strtotime。

第二個 URL,討厭的一個。

http://www.example.com/casas/casas_en_malaga/malaga/malaga/
嚴格的標准:只有變量應該在/var/www/vhosts/eldeposit.com/httpdocs/protected/helpers/Search.php的第1398行通過引用傳遞
/casas/casas_en_malaga/malaga/malaga/venta-vivienda-29-473-24693-0-0

這必須刪除具有嚴格標准錯誤的部分。 我不知道它是否可以用正則表達式完成,或者我最好在 php 中編程

1) Use this rule -- it will remove function.strtotime from end of URL (by using 301 Permanent Redirect) regardless of how deep that part is in URL (ie it will work for example.com/something/function.strtotime as well如example.com/one/two/three/function.strtotime )。

RewriteEngine On
RewriteBase /

RewriteRule ^(.*)function\.strtotime $1 [L,R=301]

2) 使用 .htaccess 無法解決此問題。 這是您的 PHP 代碼中的錯誤(聽起來您已經直接傳遞了值,而不是先將其分配給變量並傳遞變量)並且必須在 PHP 代碼中修復。

對於第一個你可以做

RewriteRule fincas-rusticas/finca-rustica_en_alacant-alicante/lalacanti/alicante/function.strtotime fincas-rusticas/finca-rustica_en_alacant-alicante/lalacanti/alicante/ [L]

對於第二個,我必須假設這個 URL 已經被重寫了,因為嚴格的標准錯誤是 PHP 錯誤。 這意味着您的地址在某處已處理。

如果 URL 應該被腳本處理為重定向到,我想你可以參考: 嚴格標准:只有變量應該通過引用傳遞

如果 URL 應該產生一個禁止的錯誤,你可以這樣做

RewriteRule casas/casas_en_malaga/malaga/malaga/ - [F]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM