douhuigang9550 2015-07-15 14:01
浏览 48

PHP 301重定向链接列表

I have an interesting situation. A site I was working on used to be in wordpress and there was a plugin called simple 301 redirects - what it did, was... create redirects for a list of pages that were hosted elsewhere...

EXAMPLE If I typed in, "http://www.example.com/specificPage" - it would redirect me to a landing page at another location- "http://subdomain.example.com/specificPage". I have a WHOLE list of these pages that need to have the redirect.

I know the basic one:

<?php 
header("HTTP/1.1 301 Moved Permanently"); 
header("Location: http://www.New-Website.com/"); 
?>

How would that work for a big long list of say 35 of these "unique" links? Would I have to create each of them and redirect them? Or can i create just one page, maybe in connection with the HTACCESS file, and a simple code to do it for me?

Any suggestions would be greatly appreciated.

  • 写回答

3条回答 默认 最新

  • douqian1835 2015-07-15 14:05
    关注

    Having a SEO-agency background i can say: Do it with 35 lines in .htaccess and you will be happy with that.

    We have had htaccess files with far more than 2.000 301-redirects in it from time to time and there is nothing better.

    Hope, this will help...

    [EDIT] Some demo code

    RewriteEngine on 
    RewriteRule ^specificPage http://subdomain.example.com/specificPage [R=301,L, NC]
    RewriteRule ^otherSpecificPage http://subdomain.example.com/otherSpecificPage [R=301,L, NC]
    

    In some cases - depends on your specific webserver - you need to write with a ^/

    RewriteEngine on 
    RewriteRule ^/specificPage http://subdomain.example.com/specificPage [R=301,L, NC]
    RewriteRule ^/otherSpecificPage http://subdomain.example.com/otherSpecificPage [R=301,L, NC]
    
    评论

报告相同问题?

悬赏问题

  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题
  • ¥15 linux驱动,linux应用,多线程