如何设置 .htaccess 以重写到不同的文件夹
我正在将我的网站移动到新主机,但我需要让当前的服务器继续处理请求(并非所有文件都可以移动到新服务器)。 因此,我向旧服务器 (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其配置为名为
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 invhosts.conf
). Giveold.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.请尝试按如下方式修复您的 .htaccess 配置:
Please try to fix your .htaccess config as follows: