网页服务器必须是 Apache
【情况一】
| http://your_domain.com/wordpress >> http://your_domain.com/blog |
让连接到 /wordpress 的连结重新寻址到 /blog,包含下层路径
例如:http://vinta.ws/wordpress/?p=334 会被指向 http://vinta.ws/blog/?p=334
在 .htaccess 中要这么写:
Redirect /wordpress http://your_domain.com/blog |
如果有安装 mod_rewrite 模块的话,也可以这样写:
RewriteEngine on RewriteRule ^wordpress(.*)$ /blog$1 [R=301,L] |
【情况二】
http://your_domain.com/wordpress >> http://your_domain.com |
让连接到 /wordpress 的链接重新寻址到 根目录,包含下层路径(如 /wordpress/xxx)
在 .htaccess 中要这么写:
| Redirect /wordpress http://your_domain.com |
如果有安装 mod_rewrite 模块的话,也可以这样写:
RewriteEngine on RewriteRule ^wordpress(.*)$ $1 [R=301,L] |
【情况三】
http://old_domain.com/ >> http://new_domain.com/ |
让连接到 旧网址 的连结重新寻址到 新网址,前提是你必须是旧网址的拥有者
建议让 旧网址 和 新网址 包持相同的目录结构
把 .htaccess 放到 旧网址 的根目录,然后要这么写:
RewriteEngine on RewriteRule (.*) http://new_domain.com/$1 [R=301,L] |
【情况四】
http://www.your_domain.com/ >> http://your_domain.com/ |
统一你的网址,不要出现 www
由 www.your_domain.com 进入的连结一律重新指向 your_domain.com
可以在 .htaccess 中这么写:
RewriteEngine on RewriteCond %{HTTP_HOST} ^www.your_domain.com$ [NC] RewriteRule ^(.*)$ http://your_domain.com/$1 [R=301,L] |
比如本站-庄河SEO就是这样做的:
| RewriteEngine on RewriteCond %{HTTP_HOST} ^www.zhuangheseo.com$ [NC] RewriteRule ^(.*)$ http://zhuangheseo.com/$1 [R=301,L] |
你浏览的文章是 - 《.htaccess文件应用技巧总结》!
文章出处:http://zhuangheseo.com/seo_l.html