Apache中301重定向的配置代码

Aine ·
更新时间:2024-09-21
· 969 次阅读

新建.htaccess文件,输入下列内容(需要开启mod_rewrite):
1)将不带WWW的域名转向到带WWW的域名下
代码如下:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^jb51.net [NC]
RewriteRule ^(.*)$ //www.jb51.net/$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跳转到主域名的方法



301重定向 重定向 Apache 301

需要 登录 后方可回复, 如果你还没有账号请 注册新账号
相关文章