.htaccess Htaccess 301重定向Htaccess或php
我在Htaccess中有一个重写规则,动态URL如下所示.htaccess Htaccess 301重定向Htaccess或php,.htaccess,mod-rewrite,redirect,.htaccess,Mod Rewrite,Redirect,我在Htaccess中有一个重写规则,动态URL如下所示 RewriteRule ^cartoon-([^-]*)-([^-]*)\.html$ /fm /cart_new?r_id=$1&location=$2 [L] 此规则导致URL为http://localhost/fm/cartoon-34-singapore.html 现在,我的客户希望将此URL更改为http://localhost/fm/singapore/34/goofie我写了.htaccess作为 RewriteR
RewriteRule ^cartoon-([^-]*)-([^-]*)\.html$ /fm
/cart_new?r_id=$1&location=$2 [L]
此规则导致URL为http://localhost/fm/cartoon-34-singapore.html
现在,我的客户希望将此URL更改为http://localhost/fm/singapore/34/goofie
我写了.htaccess作为
RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /fm
/cart_new?location=$1&r_id=$2&cartooname=$3 [L]
上面的重写工作正常,但客户端希望所有旧的URL都像http://localhost/fm/cartoon-34-singapore.html
应重定向到http://localhost/fm/singapore/34/goofie
这让我快发疯了。我试过各种方法,但似乎都不管用 在PHP代码中,您可以执行如下重定向操作:
header ('HTTP/1.1 301 Moved Permanently');
header("Location: {$rebuilt_url}");
此处
$rebuilded\u ur
将设置为http://localhost/fm/singapore/34/goofie
通过查询您的数据库。旧URLhttp://localhost/fm/cartoon-34-singapore.html
中没有卡通名称。因此它无法重定向到http://localhost/fm/singapore/34/goofie
如果URL模式匹配,我们是否可以通过发送301 redirect头在PHP中以某种方式更改URL?是的,可以在PHP中执行,然后在PHP中执行重定向。您可以添加此作为答案,以便我可以接受相同的答案。像charm一样工作:)