准确重定向所有网址,只需更改域名 [英] Redirect all urls exactly, just change domain name

查看:30
本文介绍了准确重定向所有网址,只需更改域名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大约 1000 个 URL 的网站.该网站正在转移到不同的域名.否则,URL 将完全相同.我想合并一个 htaccess 或某种规则,一举对所有 URL 进行 301 重定向.它本质上会将域名替换为 301 重定向.

I have a website with roughly 1K URLs. The website is moving to a different domain name. The URLs will be the exact same though, otherwise. I'd like to incorporate an htaccess or some kind of rule that does a 301 redirect for all URLs in one fell swoop. It would essentially replace the domain name as a 301 redirect.

示例:当前网址:domain.com/blog/post-1.html重定向至:newdomain.com/blog/post-1.html

Example: Current URL: domain.com/blog/post-1.html Redirect To: newdomain.com/blog/post-1.html

这作为 301 重定向执行.我该怎么做?谢谢,

And that performed as a 301 redirect. How would I do that? Thanks,

推荐答案

将此规则放在 domain.comDOCUMENT_ROOT/.htaccess 文件中:

Place this rule in your DOCUMENT_ROOT/.htaccess file of domain.com:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)domain\.com$ [NC]
RewriteRule ^ http://newdomain.com%{REQUEST_URI} [L,R=301]

这篇关于准确重定向所有网址,只需更改域名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆