我正在将整个网站迁移到新的服务器,并需要设置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 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 重定向到的 http://NewDomain.com/about http://OldDomain.com/this-is-the-title 重定向到 http://NewDomain.com/this-is-the-title 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]
相关推荐
最新文章