首页 > 开发 > Apache > 正文

apache 与htaccess 301重定向代码

2020-10-12 18:50:34
字体:
来源:转载
供稿:网友

新建.htaccess文件,输入下列内容(需要开启mod_rewrite):

1)将不带www的域名转向到带www的域名下

  1. options +followsymlinks  
  2. rewriteengine on  
  3. rewritecond %{http_host} ^embeta.com [nc]  
  4. rewriterule ^(.*)$ $1 [l,r=301] 

2)重定向到新域名

  1. options +followsymlinks  
  2. rewriteengine on  
  3. rewriterule ^(.*)$ $1 [l,r=301] 

3)使用正则进行301转向,实现伪静态

  1. options +followsymlinks  
  2. rewriteengine on  
  3. rewriterule ^news-(.+).html1  

将news.php?id=123这样的地址转向到news-123.html

4、apache下vhosts.conf中配置301重定向,为实现url规范化,通常将不带www的域名转向到带www域名,vhosts.conf中配置为:

  1.   
  2. servername documentroot /home/embeta  
  3.   
  4.   
  5. servername embeta.com  
  6. redirectmatch permanent ^/(.*) $1  
  7.  

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表