htaccess 将所有页面重定向到单个页面

发布于 2024-09-15 15:05:58 字数 228 浏览 1 评论 0原文

我想使用 htaccess 文件将所有旧域请求重定向到新域。以下是我正在使用的内容,但如果该页面不在新网站上,它就不起作用。例如,谷歌索引 about.htm 在旧网站上,但在新网站上它不存在。我希望它在所有情况下都能找到根源。我知道这对于 seo 来说并不理想,但我不想要任何 404。有什么建议吗?

Redirect 301 / http://www.thenewdomain.com/

I want to redirect all of my old domain request to my new domain using htaccess file. Below is what I am using but it does not work if the page is not on the new site. For example google index about.htm on the old site but on the new site it does not exist. I would like it to just go to the root in all cases. I know this is not ideal for seo but I don't want any 404s. Any suggestions?

Redirect 301 / http://www.thenewdomain.com/

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

維他命╮ 2024-09-22 15:05:58

如果您的目标是将所有页面重定向到单个维护页面(正如标题也可能暗示的那样),则使用:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.php$ 
RewriteCond %{REMOTE_HOST} !^000\.000\.000\.000
RewriteRule $ /maintenance.php [R=302,L] 

其中 000 000 000 000 应替换为 您的 IP 地址

来源:

http://www.techiecorner。 com/97/redirect-to-maintenance-page-during-upgrade-using-htaccess/

If your aim is to redirect all pages to a single maintenance page (as the title could suggest also this), then use:

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.php$ 
RewriteCond %{REMOTE_HOST} !^000\.000\.000\.000
RewriteRule $ /maintenance.php [R=302,L] 

Where 000 000 000 000 should be replaced by your ip adress.

Source:

http://www.techiecorner.com/97/redirect-to-maintenance-page-during-upgrade-using-htaccess/

万人眼中万个我 2024-09-22 15:05:58

您是否试图让 old.com/about.htm 的访问者转到 new.com/about.htm ?如果是这样,您可以使用 .htaccess 中的 mod_rewrite 规则来执行此操作:

RewriteEngine 开启

RewriteRule ^(.*)$ http://www.thenewdomain.com/$1 [R=permanent,L]

Are you trying to get visitors to old.com/about.htm to go to new.com/about.htm? If so, you can do this with a mod_rewrite rule in .htaccess:

RewriteEngine on

RewriteRule ^(.*)$ http://www.thenewdomain.com/$1 [R=permanent,L]

打小就很酷 2024-09-22 15:05:58

这会将旧主机的所有内容定向到新主机的根目录:

RewriteEngine on
RewriteCond %{http_host} ^www.old.com [NC,OR]
RewriteCond %{http_host} ^old.com [NC]
RewriteRule ^(.*)$ http://www.thenewdomain.org/ [R=301,NC,L]

This will direct everything from the old host to the root of the new host:

RewriteEngine on
RewriteCond %{http_host} ^www.old.com [NC,OR]
RewriteCond %{http_host} ^old.com [NC]
RewriteRule ^(.*)$ http://www.thenewdomain.org/ [R=301,NC,L]
忆离笙 2024-09-22 15:05:58
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ "http://www.thenewdomain.com/" [R=301,L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ "http://www.thenewdomain.com/" [R=301,L]
三生路 2024-09-22 15:05:58

HTAccess 将网站的所有页面发送到一页。这对我有用:

ErrorDocument 404 /page-name.php

或对不同的域...

RedirectMatch 301 ^/.*$ https://www.example-domain.com/page-name.php

HTAccess to send all pages of a website to one page. This worked for me:

ErrorDocument 404 /page-name.php

or to a different domain...

RedirectMatch 301 ^/.*$ https://www.example-domain.com/page-name.php
℉絮湮 2024-09-22 15:05:58

为当前不在您网站上的页面添加此...

ErrorDocument 404 http://example.com/

以及您的重定向 301 / http://www.thenewdomain.com/ 应该涵盖所有基础...

好运气!

Add this for pages not currently on your site...

ErrorDocument 404 http://example.com/

Along with your Redirect 301 / http://www.thenewdomain.com/ that should cover all the bases...

Good luck!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文