htaccess 将旧站点重定向到 2 个不同的域

发布于 2024-07-19 02:38:47 字数 471 浏览 5 评论 0原文

好的,场景如下:

我在主机的根目录上有一个博客,然后我在名为 fsGallery 的子文件夹中托管了一些应用程序。 现在,我为我的博客购买了一个新域,为我的应用程序购买了另一个域。 我想知道正确的 htaccess 301 重定向,以便我将旧目录重定向到各自的新域,

这是一个示例目录结构:

root/
  /app
  [blog]

尝试: 将 /app 重命名为 newdomainforapp.com redir [blog] 到 newdomainforblog.com

最初,我的应用程序曾经接受这样的 url 参数: app/user/1234567

所以我也想: redir /app/user/{动态 int 参数} 到 newdomainforapp.com/profile/{动态 int 参数}

任何人都可以帮助我 plox?

ok so heres the scenario:

i got a blog on the root directory of my host then i hosted some app on a subfolder named fsGallery. now, i bought a new domain for my blog and another domain for my app. ii would like to know the proper htaccess 301 redirects in order for me to redirect the old directories to their respective new domains

here's a sample dir structure:

root/
  /app
  [blog]

trying to:
redir /app to newdomainforapp.com
redir [blog] to newdomainforblog.com

also, originally, my app used to accept url parameters like this:
app/user/1234567

so i would also like to:
redir /app/user/{dynamic int parameter} to newdomainforapp.com/profile/{dynamic int parameter}

can anyone help me plox?

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

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

发布评论

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

评论(2

机场等船 2024-07-26 02:38:47

可能与编程无关,但无论如何:执行此操作的正确方法是在虚拟主机配置文件中(即在 ... ; 部分),而不是在 .htaccess 文件中。 要使用的指令是

 RedirectMatch permanent /app/user/([0-9+]) http://newdomainforapp.com/profile/$1
 Redirect permanent /app http://newdomainforapp.com
 Redirect permanent / http://newdomainforblog.com

Possibly not programming-related, but anyway: the proper way to do this is in the virtual host configuration file (i.e. in the <VirtualHost *:80> ... </VirtualHost> section), not in an .htaccess file. The directives to use are

 RedirectMatch permanent /app/user/([0-9+]) http://newdomainforapp.com/profile/$1
 Redirect permanent /app http://newdomainforapp.com
 Redirect permanent / http://newdomainforblog.com
泪是无色的血 2024-07-26 02:38:47

看来 RewriteRule 应该可以正常工作。

RewriteEngine on
RewriteRule ^/?app/user/([0-9]+) http://newdomainforapp.com/profile/$1 [R=301,L]
RewriteRule ^/?app(/(.*))?$ http://newdomainforapp.com/$2 [R=301,L]
RewriteRule ^/?(.*) http://newdomainforblog.com/$1 [R=301,L]

您可能需要尝试使用这些组来正确重定向文章。

It seems RewriteRules should work fine.

RewriteEngine on
RewriteRule ^/?app/user/([0-9]+) http://newdomainforapp.com/profile/$1 [R=301,L]
RewriteRule ^/?app(/(.*))?$ http://newdomainforapp.com/$2 [R=301,L]
RewriteRule ^/?(.*) http://newdomainforblog.com/$1 [R=301,L]

You'll probably need to play around with the groups to redirect articles properly.

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