问题描述
我在.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 http://localhost/fm/cartoon-34-singapore.html
现在我的客户想要这个URL更改为的http://本地主机/ FM /新加坡/ 34 / goofie
我写的.htaccess为
Now my client want to change this URL to http://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 http://localhost/fm/singapore/34/goofie
by querying your database.
这篇关于.htaccess的301重定向htaccess的或php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!