您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

php url 跳转老目录到新目录

2024/4/4 21:34:20发布8次查看
一个关于手机的网站,用wordpress基板。
原先的htacess 放在主目录下 /var/www/html
rewriteengine onrewritebase /rewriterule ^items/products/(\d+)/(.*)?$ items/products.php?number=$1&name=$2 [qsa,l]rewritecond %{request_filename} !-frewritecond %{request_filename} !-drewriterule . /index.php [l]
新建一个 .htacess 放在子目录下 `/var/www/html/2014·
rewriteengine onrewritebase /2014/rewriterule ^phone/products/(\d+)/(.*)?$ phone/products.php?number=$1&name=$2 [qsa,l]rewritecond %{request_filename} !-drewritecond %{request_filename} !-frewriterule (.*) $1.php [l]
现在要把旧的url地址永久跳转到新的url地址里
www.example.com/items/products/1234/iphone-5c
=>
www.example.com/2014/phone/products/1234/iphone-5c
我尝试在items/products.php里把源代码修改为

居然报错 request exceeded the limit of 10 internal redirects due to probable configuration error. use 'limitinternalrecursion' to increase the limit if necessary. use 'loglevel debug' to get a backtrace.
把源代码改回原来的,添加 echo 'http://www.example.com/2014/phone/products/'.$_get['number'].'/'.$_get['name'];
页面正常显示http://www.example.com/2014/phone/products/1234/iphone-5c,鼠标全选右键打开url在新窗口,可以正常跳转,但为什么apache回报错?
然后再尝试修改
然后主目录下的那个htacess
rewriterule ^item/products/(\d+)/(.*)?$ items/products.php?number=$1&name=$2 [qsa,l]
变成
rewriterule ^2014/phone/products/(\d+)/(.*)?$ items/products.php?number=$1&name=$2 [qsa,l,r=301]
这次居然跳转到wordpress的 404 页面了。
郁闷,到底要怎么做,才能正常跳转?
回复讨论(解决方案) 1)header跳转之所以报错,写法错误。header(location:$url );
另外里面的$_get这几个如果不存在,又没有设置报错级别,那么还是容易报错
2)重写文件.htaccess 无需放到 /2014/目录,直接在原来的 / 重写即可
#by default7#zbphp.comrewriteengine onrewritecond %{request_filename} !-drewritecond %{request_filename} !-frewriterule ^items/products/(\d+)/(.+)?$ 2014/phone/products/$1/$2/ [l,r=301]rewriterule ^2014/phone/products/(\d+)/(.+)?$ phone/products.php?number=$1&name=$2 [pt,qsa,l]rewriterule (.*) $1.php [l]
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product