简体   繁体   English

如何将旧域的目录索引重定向到 .htaccess 中的新域页面?

[英]How can i redirect the directory index of my old domain to a new domain page in .htaccess?

My general question is how can I redirect a directory index of my old domain to a new domain directory index in the same way i would a another page on the site?我的一般问题是如何将旧域的目录索引重定向到新的域目录索引,就像我将网站上的另一个页面重定向一样?

I am able on how to all individual pages on my new domain through one to a redirect.我能够了解如何通过一个重定向访问我的新域上的所有单独页面。 My htacess code looks like this我的 htacess 代码看起来像这样

RewriteCond %{HTTP_HOST} ^example-page.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.example-page.com


DirectoryIndex front_page.php    

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule   /about    /about_page.php

redirect 301 /about https://www.new_domain_example.com/about

Where i am having trouble is redirecting the homepage or directory index which is found at https://www.example-page.com .我遇到问题的地方是重定向位于https://www.example-page.com的主页或目录索引。

I have tried我试过了

redirect 301 /  https://www.example-page.com

Also

Redirect 301 http://www.example-page.com   http://www.new_domain.com 

The first doesnt work because it seems to all pages to this domain which is undesired.第一个不起作用,因为它似乎对这个域的所有页面都是不受欢迎的。 All i want is to redirect the DirectoryIndex/ homepage found at the url to the new url.我只想将在 url 找到的 DirectoryIndex/ 主页重定向到新的 url。

The second attempt doesnt work either.第二次尝试也不起作用。 At this point im quite confused as to what i could do the only thing that occurs to me is, externalising the home page.在这一点上,我对我能做什么感到很困惑,我唯一想到的就是将主页外部化。 so that it looks like.这样看起来像。

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule   /front    /front_page.php

redirect 301 /front https://www.new_domain_example.com/front

Im sure this is not necessary and im missing something.我确定这不是必需的并且我遗漏了一些东西。 How would you approach redirecting the front page that is as a directory index in this code without doing something that breaks the rest of my code?在不破坏我的代码的 rest 的情况下,您将如何重定向作为此代码中的目录索引的首页?

Any help or insights to what i'm doing wrong would be much appreciated.对我做错了什么的任何帮助或见解将不胜感激。

Try if you only want to redirect the home page:如果您只想重定向主页,请尝试:

RewriteCond %{REQUEST_URI} ^\/.front_page\.php$
RewriteCond %{HTTP_HOST} !^newdomain\.com$
RewriteRule ^ https://newdomain.com%{REQUEST_URI} [R=301,L]

If you want to redirect everything in the old domain to the new one:如果您想将旧域中的所有内容重定向到新域:

RewriteCond %{HTTP_HOST} !^newdomain\.com$
RewriteRule ^ https://newdomain.com%{REQUEST_URI} [R=301,L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM