.htaccess做301重定向的几种方法【亲测有效】

1、用.htaccess301将index.html、index.php等重定向到主域名:
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.abc.org/ [R=301,L]

2、内页301定到首页
# BEGIN WordPress
RewriteCond %{HTTP_HOST} ^facebeautyhk.com$
RewriteRule ^liaochenghao.html$ http://facebeautyhk.com/ [R=301,L]
RewriteRule ^liaochenghao.html/$ http://facebeautyhk.com/ [R=301,L]
# END WordPress

3、用301将绑定的其他域名重定向到主域名: 注意这个地方,有RewiteEnginee on这句,
RewriteEngine on
RewriteCond %{HTTP_HOST} ^其他域名.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.其他域名.com$
RewriteRule ^(.*)$ http://www.主域名.com/$1 [R=301,L]

4、去掉index.php,不带www跳转到带www
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^khlmarineproducts.com [NC]
RewriteRule ^(.*)$ http://www.khlmarineproducts.com/$1 [L,R=301]
RewriteRule ^index\.php$ http://www.khlmarineproducts.com/ [R=301,L]

5、修改.htaccess强制HTTP重定向为HTTPS链接
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]

你可能感兴趣的:(网站优化)