繁体   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