通过 httpd.conf 或 .htaccess 将我网站的新版本发送到我的 IP 地址

Serve the new version of my website to my IP address via httpd.conf or .htaccess

我正在为我的基于 wp 的网站进行全面更新(从头开始完全重写)。

我想知道是否可以为旧网站提供服务,但为我的 IP 地址提供新网站。

有没有办法通过 httpd.conf 或 .htaccess 实现?

If (IP_Address = 123.456.789) then
    # Serve content from /home/website.com/public_html/
else
    # Serve content from /home/new-website.com/public_html/
end if

谢谢!

使用 mod_rewrite 你可以使用 %{REMOTE_ADDR} 变量来检测远程 ip 是什么,并根据它更改你的内容根目录:

RewriteEngine on

RewriteCond %{REMOTE_ADDR} ^127.0.0.1$
RewriteCond %{REQUEST_URI} !^/newsite/index\.php$
RewriteRule ^ /newsite/index.php

RewriteCond %{REMOTE_ADDR} !^127.0.0.1$
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteRule ^ /index.php