.htaccess的301重定向htaccess的或php

编程入门 行业动态 更新时间:2024-10-28 09:16:47
本文介绍了.htaccess的301重定向htaccess的或php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在.htaccess的重写规则,如下为动态URL

I have a rewrite rule in Htaccess as below for a dynamic URL

RewriteRule ^cartoon-([^-]*)-([^-]*)\.html$ /fm /cart_new?r_id=$1&location=$2 [L]

此规则将导致进入网址为的http://localhost/fm/cartoon-34-singapore.html

This rule results into URL as localhost/fm/cartoon-34-singapore.html

现在我的客户想要这个URL更改为的http://本地主机/ FM /新加坡/ 34 / goofie 我写的.htaccess为

Now my client want to change this URL to localhost/fm/singapore/34/goofie and i wrote .htaccess as

RewriteRule ^([^/.]+)/([^/.]+)/([^/.]+)/?$ /fm /cart_new?location=$1&r_id=$2&cartooname=$3 [L]

以上重写工作正常,但客户端希望所有的旧网址就像即的http://localhost/fm/cartoon-34-singapore.html 应301重定向的http://本地主机/ FM /新加坡/ 34 / goofie

这是推动我疯了。我曾尝试过各种东西,但似乎没有工作。

This is driving me crazy. I have tried various things but none seems working.

推荐答案

在你的PHP code,你可以做这样的事情的重定向:

In your PHP code you can do something like this for redirection:

header ('HTTP/1.1 301 Moved Permanently'); header("Location: {$rebuilt_url}");

下面 $ rebuilt_ur 将被设置为的http://本地主机/ FM /新加坡/ 34 / goofie 通过查询数据库。

Here $rebuilt_ur will be set to localhost/fm/singapore/34/goofie by querying your database.

更多推荐

.htaccess的301重定向htaccess的或php

本文发布于:2023-10-31 17:11:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1546741.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重定向   htaccess   php

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!