简体   繁体   English

将所有页面重定向到新域 htaccess

[英]Redirect all pages to a new domain htaccess

I want to redirect my entire website to a new unique address/domain without respecting the relation between filenames.我想将我的整个网站重定向到一个新的唯一地址/域,而不考虑文件名之间的关系。

I don't want olddomain.com/foo.html to be redirected to newdomain.com/foo.html .我不希望olddomain.com/foo.html被重定向到newdomain.com/foo.html

I want this result with a htaccess file:我想要一个带有 htaccess 文件的结果:

olddomain.com/foo.html => newdomain.com
olddomain.com/foo/bar.html => newdomain.com
olddomain.com/a/b/c/moo.html => newdomain.com

The Redirect 301 function of htaccess does exactly what I don't want. htaccess 的Redirect 301 function 正是我不想要的。

How I can proceed?我该如何继续?

Answer to the RavinderSingh13's comment:回答 RavinderSingh13 的评论:

This is what I tried so far:这是我到目前为止所尝试的:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ https://www.newdomain.com/$1 [R=301,L]

And:和:

Redirect 301 / https://www.newdomain.com/

And also:并且:

RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.comfr$
RewriteRule ^/?$ "https\:\/\/www\.newdomain\.com/" [R=301,L]

Found the answer by reviewing my question:通过查看我的问题找到了答案:

I just had to remove the $1 at the end as it's a regular expression, it contains the value of the reference script name.我只需要删除最后的$1 ,因为它是一个正则表达式,它包含参考脚本名称的值。

So the working solution for me is:所以对我来说可行的解决方案是:

RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ https://www.newdomain.com/ [R=301,L]

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

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