新建.htaccess文件,输入下列内容(需要开启mod_rewrite):
1)将不带WWW的域名转向到带WWW的域名下
复制代码 代码如下:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^jb51.net [NC]
RewriteRule ^(.*)$ https://www.cnhackhy.com/$1 [L,R=301]
2)重定向到新域名
复制代码 代码如下:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^(.*)$ http://www.baidu.com/$1 [L,R=301]
3)使用正则进行301重定向,实现伪静态
复制代码 代码如下:
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^news-(.+)\.html$ news.php?id=$1
将news.php?id=123这样的地址转向到news-123.html
Apache下vhosts.conf中配置301重定向
为实现URL规范化,SEO通常将不带WWW的域名转向到带WWW域名,vhosts.conf中配置为:
复制代码 代码如下:
<VirtualHost *:80>
ServerName www.baidu.com
DocumentRoot /home/fari001Com
</VirtualHost>
<VirtualHost *:80>
ServerName faribaidu.com
RedirectMatch permanent ^/(.*) http://www.baidu.com/$1
</VirtualHost>
Apache下除了以上2种方法,还有其他配置方法和可选参数,建议阅读Apache文档。
您可能感兴趣的文章:
- Apache实现禁止中文浏览器访问与301重定向的方法
- apache将不带www域名301重定向到带www的域名的配置方法
- windows中apache 301页面跳转实现方法
- Apache Rewrite实现URL的301跳转和域名跳转
- apache+php完美解决301重定向的两种方法
- 301重定向代码合集(iis,asp,php,asp.net,apache)
- 完美解决IIS和APACHE的301重定向(带参数)
- 解析网站301重定向的实现方法,包括iis,apache,asp,php的方法
- Apache的Rewrite设置多域名301跳转到主域名的方法
本文由 华域联盟 原创撰写:华域联盟 » Apache中301重定向的配置代码
转载请保留出处和原文链接:https://www.cnhackhy.com/44272.htm