重定向到另一个网站

问题描述 投票:0回答:1

我有两个网站https://abc1.com https://example1.com

Example1是一个电子商务网站。让我们在网站上说产品链接是https://example1.com/products/123456.html

现在我分享产品和分享链接是https://abc1.com/products/123456.html

当用户点击链接时,它应该重定向到https://example1.com/products/123456.html

对于手动静态页面,每个链接都可以。但我想动态地想要它。您可以在电子商务网站中了解到会有大量产品不断更新。因此无论产品ID将与abc.com动态放置,它都应该重定向到example1.com。

我必须通过js.like https://abc1.com/probucts/xyz123.html - >重定向到一个页面,其中js,text / picture将是 - > [重定向] - > https://example1.com/products/xyz123.html

如果有人可以提供帮助。

javascript php html url-redirection
1个回答
0
投票

您将需要使用.htaccess,您需要在.htaccess网站的根目录中创建一个名为abc1.com的文件,其内容如下:

RewriteEngine on
RewriteRule ^/products/([0-9]+).html$ https://example1.com/products/$1.html [R=301,NC,L]

这会重定向每个URL,如:https://abc1.com/products/123456.html 对此:https://example1.com/products/123456.html

编辑:

如果您需要通过JS重定向,您只需将URL重写为单个页面:

RewriteEngine on
RewriteRule ^/products/([0-9]+).html$ /redirect.html?id=$1 [NC,L]

redirect.html里面使用id参数放置JS重定向代码

© www.soinside.com 2019 - 2024. All rights reserved.