如何设置 .htaccess 以重写到不同的文件夹

发布于 2024-08-27 07:22:49 字数 621 浏览 5 评论 0原文

我正在将我的网站移动到新主机,但我需要让当前的服务器继续处理请求(并非所有文件都可以移动到新服务器)。 因此,我向旧服务器 (old.mydomain.com) 添加了一个停放域,并且希望将所有对其的请求写入旧站点的文件中。

我的旧网站 (mydomain.com) 内部托管在一个文件夹 (/public_html/mydomain/) 中,我希望将所有对 old.mydomain.com 的请求重写到同一文件夹中。 因此,如果 mydomain.com/blog 位于 /public_html/mydomain/blog 内部,我现在希望 old.mydomain.com/blog 也位于到达 /public_html/mydomain/blog

这是我尝试使用的 .htaccess:

RewriteCond %{HTTP_HOST} ^old\.mydomain\.com/*
RewriteRule ^(.*)$ mydomain/$1 [NC,L] 

但由于某种原因,一旦我在重写规则中添加 $1 ,我就会收到内部错误。

有什么想法吗?

I'm moving my site to a new host but I need to have my current server continue to handle requests (not all files can be moved to the new server).
So I added a parked domain to my old server (old.mydomain.com) and I want all requests to it to be written to the files from the old site.

My old site (mydomain.com) was hosted internally in a folder (/public_html/mydomain/) and I want all requests to old.mydomain.com to be rewritten to the same folder.
So if mydomain.com/blog was internally at /public_html/mydomain/blog, I now want old.mydomain.com/blog also to reach /public_html/mydomain/blog.

Here is the .htaccess that I'm trying to use:

RewriteCond %{HTTP_HOST} ^old\.mydomain\.com/*
RewriteRule ^(.*)$ mydomain/$1 [NC,L] 

But for some reason as soon as I add the $1 in the rewrite rule I get an internal error.

Any ideas?

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

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

发布评论

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

评论(2

執念 2024-09-03 07:22:49

将其配置为名为 old.mydomain.com 的单独虚拟主机,并确保它位于虚拟主机定义中的 *.mydomain.com 之前(即 vhosts.conf 中的较高位置) )。为 old.mydomain.com 提供与您之前的域相同的 DocumentRoot。

.htaccess 是最消耗处理器资源的网页服务方式,只有在没有其他可用选项时才应使用。

Configure this as a separate vhost called old.mydomain.com and ensure it comes before *.mydomain.com in your vhost definitions (i.e. higher in vhosts.conf). Give old.mydomain.com the same DocumentRoot as your previous domain had.

.htaccess is the most processor intensive way to serve a webpage, and should only be used there are no other options available.

夜司空 2024-09-03 07:22:49

请尝试按如下方式修复您的 .htaccess 配置:

RewriteCond %{HTTP_HOST} ^old\.mydomain\.com$
RewriteRule ^(.*)$ /public_html/mydomain/$1 [NC,L]

Please try to fix your .htaccess config as follows:

RewriteCond %{HTTP_HOST} ^old\.mydomain\.com$
RewriteRule ^(.*)$ /public_html/mydomain/$1 [NC,L]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文