Categorized | 网络技术

.htaccess中RedirectMatch的301,URL广泛匹配如何设置?

发布于 2012年07月22日 更新于 2012年07月27日 

在wordpress中,我们一般很少会改动网站的固定链接,不过如果改变了固定链接,一定要做好301重定向,要不然SE进来都是404代码,问题很严重。

比如我们之前的固定链接,是https://sunweiwei.com/reed/144.html 这种形式,改完固定链接后,是https://sunweiwei.com/144/ 这种形式。

这是我们就需要做好301转向了。

在.htaccess中,Redirect重定向包含(不支持正则匹配)

第一个是permanent:永久性301重定向;
第二个是temp:临时重定向状态码,即返回302;
第三个是seeother:此参数表示“参见”的含义,即本资源已经被另外一个更好的资源替代了;

Redirect [permanent,temp,seeother]/service http://www.baidu.com/service

RedirectMatch函数支持正则

RedirectMatch 301 reed\/(.*)\.html$ https://sunweiwei.com/$1/
RedirectMatch 301 reed\/tag\/(.*)$ https://sunweiwei.com/tag/$1/

 

附注:如果需要A301→B:有几种写法

RewriteRule ^A$ B [L,R=301]
RedirectMatch 301 ^A$ B
Redirect 301 A B

 

 

看了此文的人貌似还看了这些:

  • 密码保护:出场教程 2017-10-24
  • 易语言curl支持库与WinHttpRequest、WinInet、互联网支持库http访问对比测试 2014-04-30
  • 线程中使用正则表达式cpu占用100%解决方案 2014-05-29
  • 2025.7.10更新:领势MX4200路由器优化、避坑及mesh组网简易教程 2025-01-06
  • Centos安装L2TP+IPSec完整教程 2015-02-07
  • wininet,winhttp,xmlhttprequest,ServerXmlHttpRequest各版本区别 2015-05-22
  • lnmp下mysql 5.6内存占用过高解决方法 2015-11-02
  • Centos安装Cisco IPSec V-P-N方式 2015-02-25
  • centos安装ss多用户带前端教程 2015-02-03
  • Amazon EC2的V-P-N-PPTP搭建教程(on aws redhat6.5 X64) 2014-10-20
  • 1 Comments For This Post

    1. 缘来逝你 Says:

      顶顶呀、

    发表评论

    Time limit is exhausted. Please reload CAPTCHA.

       我相信你,不会发广告!

    斗牛SEO工具