mod_rewrite、链接、虚拟主机
看来我永远无法和 mod_rewrite 相处了... 我处于典型场景:
homepage_one.tld/impressum.php --> domain.tld?content=impressum
homepage_one.tld/projects.php --> domain.tld?content=projects
homepage_one.tld/projects/canvas.php --> domain.tld?content=projects&project=canvas
我正在离线开发,使用 VMware 上的 Ubuntu Server Edition。这意味着我的 homepage_one 要测试的本地域是: _http:///localhost:2180/homepage_one/index.php 稍后将是_http://homepage_one.tld。
<Directory /var/www/homepage_one>
RewriteEngine on
RewriteRule ^([^/]*)\.php$ index.php?content=$1 [QSA,L]
RewriteRule ^projects/(.*)\.php$ index.php?content=projects&project=$1 [QSA,L]
</Directory>
现在,当我请求网址时,所有 css / 图像链接 都已损坏*:_http://localhost:2180/homepage_one /项目/canvas.php (它寻找“homepage_one/projects/canvas/style.css”而不是“homepage_one/style.css”
stackoverflow上关于此问题的大多数答案是:使用绝对链接我尝试过,但要离线测试,我的绝对链接将是 /homepage_one/style.css,一旦我发布网站,我就必须更改所有链接。也不起作用......有什么想法吗?
It seems that I'll never get along with mod_rewrite...
I'm in the typical scenario:
homepage_one.tld/impressum.php --> domain.tld?content=impressum
homepage_one.tld/projects.php --> domain.tld?content=projects
homepage_one.tld/projects/canvas.php --> domain.tld?content=projects&project=canvas
I'm developing offline, using Ubuntu Server Edition on an VMware. That means, the local domain for my homepage_one to test is: _http:///localhost:2180/homepage_one/index.php
Later it will be _http://homepage_one.tld.
<Directory /var/www/homepage_one>
RewriteEngine on
RewriteRule ^([^/]*)\.php$ index.php?content=$1 [QSA,L]
RewriteRule ^projects/(.*)\.php$ index.php?content=projects&project=$1 [QSA,L]
</Directory>
All css / image links are *broken * now, when I'm asking for the url: _http://localhost:2180/homepage_one/projects/canvas.php
(It looks for "homepage_one/projects/canvas/style.css" instead of "homepage_one/style.css"
most answers at stackoverflow concerning this issue are: use absolute links. I tried it, but to test it offline, my absolute link would be /homepage_one/style.css and i would have to change ALL links, once I publish the website. I also tried to use the html-base tag. But this didn't work eigther.... any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
约翰尼斯,这确实是您的答案的答案:-)传统的方法列表条目是
IP name name
,例如或其他。
我还发现端口转发非常痛苦。我总是使用桥接网络或仅主机网络。我的 Windows/WMware 技能有点生疏,因为大约 5 年前我就放弃了这两者,但是 此 VMware 页面介绍了如果您使用 VMware Workstation 的话如何执行此操作。您可以对 VMware 设备执行相同的操作,但必须开始调整 VMX 文件。正如我在我的博客文章中所说(我建议您阅读该文章),我发现使用 VBox 更容易。
在桥接网络中,如果您的主机 NIC 的 MAC 地址是 00:23:18:dd:88:88 并且您的 VM 的 MAC 地址是 08:00:27:FE:FE:FE,则 VMware 网络驱动程序会对主机 NIC 进行编程以响应两者,但随后将 08:00:27:FE:FE:FE 数据包传递到 VM 的虚拟 NIC 上。因此,虚拟机就像任何其他 PC 一样参与网络,并且对于任何其他设备来说就像 PC/服务器。我在 192.168.1.0/24 私有地址空间上运行所有家庭设备,因此我只是为 192.168.1.192/26 中的虚拟机静态分配 IP。
桥接和仅主机网络的巨大优势在于,您可以使用默认端口 80,并且如果您愿意,您还可以(暂时)覆盖 myprodsite.com 的 DNS 条目以指向您的虚拟机,以便任何绝对然后,编码的
http://myprodsite.com/
URI 将在测试期间指向回虚拟机。希望这有帮助:-)
Johannes this is really an answer to your answer :-) The conventional way to list entries is
IP name name
, e.g.or whatever.
I also find port forwarding a total pain. I always use a bridged or host-only network. My Windows/WMware skills are a bit rusty as I gave up on both about 5 years ago, but this VMware page describes how to do it if you are using VMware Workstation. You can do the same with a VMware appliance but you have to start tweaking the VMX file. As I said in my blog article, which I recommend that you read, I find just easier with VBox.
In a bridged network, if you host NIC's MAC address is 00:23:18:dd:88:88 and your VM's is 08:00:27:FE:FE:FE then the VMware network driver programs the host NIC to respond to both but then passes the 08:00:27:FE:FE:FE packets onto the VM's virtual NIC. Hence the VM participates on the network just like any other PC and looks like a PC/server to any other devices. I run all my home devices on a 192.168.1.0/24 private address space, so I just statically allocate IPs for my VMs in 192.168.1.192/26.
The great advantage of bridged and host-only networks is that you can use the default port 80, and that if you want you can also (temporarily) override your DNS entry for your myprodsite.com to point to your VM, so that any absolute coded
http://myprodsite.com/
URIs will then point back to the VM during testing.Hope this helps :-)
解决方案(感谢@TerryE):
在我的例子中,使用端口转发到不同的虚拟机,我可以访问它们,如下所示:
现在我可以使用 VirtualHosts,就像在我的生产服务器上一样,并使用绝对链接。
Solution (thanks to @TerryE):
in my case, using port forwarding to different VM's, I can reach them, as followed:
now I can just use VirtualHosts, as on my production Server, and go with absolute links.