我如何使用htaccess的重定向到一个新的领域,除了站点索引? [英] How do I use htaccess to redirect to a new domain except for the site index?

查看:125
本文介绍了我如何使用htaccess的重定向到一个新的领域,除了站点索引?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在将整个网站迁移到新的服务器,并需要设置htaccess的,以便它正确地重定向旧的内容,同时处理新的内容了。

I'm working to migrate an entire site to a new server and need to setup htaccess so that it properly redirects old content while handling new content, too.

旧域是一个简单的登陆页面,包含一个index.html页和三个目录:/图像/风格/字体

The old domain is a simple landing page that consists of an index.html page and three directories: /images, /styles, /fonts.

每当有人导航到旧域,我想登陆页面加载。也就是说,如果用户导航到:

Whenever someone navigates to the old domain, I'd like the landing page to load. That is, if the user navigates to:

  • http://OldDomain.com
  • http://OldDomain.com/
  • http://OldDomain.com/index.html

然后他们继续在上述网址。

Then they remain on said URL.

任何其他情况下,的我想执行一个301重定向。例如:

In any other case, I'd like to perform a 301 redirect. For example:

  • http://OldDomain.com/about redirects to http://NewDomain.com/about
  • http://OldDomain.com/this-is-the-title redirects to http://NewDomain.com/this-is-the-title

不幸的是,我不是很似乎钉适当的定期EX pression处理的最初病例为登陆页面。

Unfortunately, I can't quite seem to nail the proper regular expression to handle the initial cases for the landing page.

推荐答案

试试这个code:

Options +FollowSymlinks -MultiViews
RewriteEngine on

# for http    
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC] 
RewriteCond %{SERVER_PORT} =80
RewriteRule . http://NewDomain.com%{REQUEST_URI} [R=301,L]

# for https
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC] 
RewriteCond %{SERVER_PORT} =443
RewriteRule . https://NewDomain.com%{REQUEST_URI} [R=301,L]

这篇关于我如何使用htaccess的重定向到一个新的领域,除了站点索引?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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