在移动设备上访问本地主机 WordPress 网站
我有一个相当简单的要求。我有一个多站点 WP 设置,我可以在其中为不同的客户创建所有新主题。我保持内容简单,因此数据库很小。我在 Mac 上的 Apache 上运行所有这些,只是默认安装。
我可以通过 localhost 访问这些多站点,但是当我尝试通过移动设备访问它们时,我没有得到任何 css 或图像。我知道这是因为移动主机正在尝试访问本地主机 URL,这对手机没有任何意义。
我可以做些什么,比如使用主机文件或 httpd.conf 来解决这个问题,以便 CSS 和图像可以在移动设备上工作?我尝试使用计算机的 IP 地址作为站点的 URL,但是使用 DHCP,这种情况会随着重新启动而改变,而且我不想继续重置 IP。
任何反馈将不胜感激。
时间
I have a fairly simple requirement. I have a multisite WP setup where I create all my new themes for various clients. I keep the content simple so the db is pretty small. I'm running all this on Apache on Mac, just the default install.
I can access these multisites through localhost, but when I try to access them through mobile, I don't get any css or images. I know it's because the mobile host is trying to access the localhost url which means nothing to the phone.
Is there anything I can do, like with say, the hosts file or the httpd.conf to sort this out so that the CSS and images will work on mobile? I tried using the IP address of the machine as the URL of the site, but with DHCP, this has changed with a reboot and I don't want to have to keep resetting the IP anyway.
Any feedback would be much appreciated.
T
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我认为你最好的选择是使用 No-IP.com 来提供你的内部主机IP是“真实的”域名。您可以使用主机文件执行相同的操作,但显然这在手机上很棘手(或者可能不可能)。
I think your best bet is to use No-IP.com to give your internal host IP a "real" domain name. You can do the same using host files, but obviously this is tricky (or maybe impossible) on a mobile phone.
如果您处于 DHCP 环境中,您始终可以使用系统名称而不是 IP。您的系统名称应始终相同,而您的计算机 IP 在每次重新启动时可能会更改。
否则,您可以使用动态 DNS 将您的免费域之一(如果有)与您的计算机链接并从任何地方访问它。
You can always use System Name instead of IP if you are in DHCP environment. Your system name should always be the same whereas your machine IP may change on every restart.
Otherwise you can use Dynamic DNS to link one of your free domain (if you have any) with your machine and access it from any where.
始终在 HTML 中使用相对 URL。
如果您有一个包含
的页面,显然该图像只会提供给访问本地计算机上的 HTML 页面的人员。
但是,如果您使用
,则图像将从与 HTML 页面获取相同的主机名/IP 地址获取,无论客户端是否看到它为“localhost”或“somehost.dynamicdns.example.com”或“123.456.789.111”。
请注意,这一切都假设您的服务器实际上会将内容提供给非本地主机客户端,尽管如果您看到的是 HTML 而不是图像和 CSS,则似乎不太可能。
Always use relative URLs within your HTML.
If you have a page containing
<a href='http://localhost/some_image.jpg'>
, obviously the image will only be served to someone accessing the HTML page on the local machine.However, if instead you use
<a href='/some_image.jpg'>
, the image will be fetched from the same hostname/IP address the HTML page was fetched from, whether the client sees it as "localhost" or "somehost.dynamicdns.example.com" or "123.456.789.111".Note that this all assumes that your server will actually serve the content to non-localhost clients, although it seems unlikely it's not if you're seeing the HTML but not the images and CSS.