寻求实现整个网站和特定页面的重定向。

huangapple go评论53阅读模式
英文:

Looking to implement redirects for entire website and a specific page

问题

我正在寻求实现以下内容。
如果有人访问站点
oldsite.com 或其下的任何页面,它们将被重定向到 newsite.com

但是
我需要 oldsite.com 上的特定页面重定向到其他地方。

oldsite.com/page 应该转到 newsite2.com

总结一下。
oldsite.com 和其下的任何页面 -> newsite.com
oldsite.com/page -> newsite2.com

我尝试使用Cpanel重定向,但似乎不适用于特定页面。

将以下内容添加到htaccess文件中:

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

但我似乎无法弄清楚如何执行最后一部分,将特定的URL重定向到另一个网站,同时保留对其他所有内容的重定向。

英文:

I am looking to implement the following.
if someone visits the site
oldsite.com or any of the pages under it they will be redirected to newsite.com

BUT
i need a specific page on oldsite.com to redirect to something else.

oldsite.com/page should go to newsite2.com

To summarize.
oldsite.com and any pages under that -> newsite.com
oldsite.com/page -> newsite2.com

I have tried using the Cpanel redirects but it doesnt seem to work for the specific page.

Adding

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

to htaccess file as well. I cannot seem to figure out how to do the last part of redirecting the specific url to another website while keeping the redirects to everything else.

答案1

得分: 1

将特定页面重定向到新域名,然后再重定向其它 'remaining' URL:

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

如果你想将其它所有内容重定向到目标域名的首页(而不是相同的 URL),可以使用以下代码:

RewriteEngine On
RewriteRule ^myspecialpage$ http://www.specialdomain.com/myspecialpage [R=301,L]
RewriteRule ^(.*)$ http://www.newdomain.com/ [R=301,L]
英文:

Redirect your specific page first, then any 'remaining' URLs second:

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

If you want to redirect everything else to the homepage (not the same URL at the target domain), then you can use:

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

答案2

得分: 0

以下是翻译好的部分:

你可以使用更“简单”的 mod_alias 指令:

重定向特定页面

RedirectMatch 301 ^/page$ https://newsite2.example/

重定向所有其他内容

RedirectMatch 301 ^/ https://newsite1.example/

请注意指令的顺序。最具体的重定向应放在第一位。

这假设旧域名没有指向与 newsite2.example 和/或 newsite2.example 相同的位置。

为避免潜在的缓存问题,您应首先使用 302(临时)重定向进行测试。

注意:永远不要混合使用 mod_alias(RedirectRedirectMatch)和 mod_rewrite(RewriteRule)的重定向,因为这可能会导致意外的冲突。(无论配置文件中的指令顺序如何,mod_rewrite 总是在 mod_alias 之前处理。)

此外,正如评论中所提到的,如果关注 SEO,那么像这样的多对一重定向到主页可能会被搜索引擎视为软 404(soft-404),这通常会给用户带来不良体验。

英文:

You can use the more "simple" mod_alias directives:

# Redirect specific page
RedirectMatch 301 ^/page$ https://newsite2.example/

# Redirect everything else
RedirectMatch 301 ^/ https://newsite1.example/

Note the order of the directives. The most specific redirect is first.

This assumes the old-domain is not pointing to the same place as newsite2.example and/or newsite2.example.

You should test first with 302 (temporary) redirects to avoid potential caching issues.

NB: Never mix redirects from both mod_alias (Redirect and RedirectMatch) and mod_rewrite (RewriteRule) since you can get unexpected conflicts. (mod_rewrite is always processed before mod_alias despite the apparent order of the directives in the config file.)

And, as mentioned in comments, if SEO is a concern then many-to-one redirects to the homepage like this are likely to be seen as soft-404s by search engines (and generally gives a bad experience for users).

huangapple
  • 本文由 发表于 2023年6月1日 23:09:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76383340.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定