如何使用mod_rewrite或mod_proxy更改localhost URL?

时间:2014-09-26 00:33:40

标签: apache .htaccess mod-rewrite mamp mod-proxy

我已经运行了MAMP(Apache:80 MySQL:3306),而我的localhost有许多包含项目的文件夹:

127.0.0.1/
127.0.0.1/test1/
127.0.0.1/test2 /

我已正确设置主机文件,因此jlc.dev/test1和jlc.dev/test2工作正常。

我遇到问题的地方是,我想让URL test1.dev在/ test1运行应用程序,使用URL test2.dev在/ test2运行应用程序。 (我不确定那里有什么正确的术语,但我希望我能说明问题。)基于this post中的一个回复,它听起来可以通过.htaccess文件中的mod_proxy或mod_rewrite实现。

我假设我做的是在我的hosts文件中将test1.dev指向127.0.0.1,并且有一个.htaccess文件来查看引用域并适当地重写到/ test1。

帮助不大?谢谢!

1 个答案:

答案 0 :(得分:0)

您需要将test1.devtest2.dev都指向127.0.0.1。然后将其添加到文档根目录中的htaccess文件中:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^([^.]+)\.dev$ [NC]
RewriteCond $1::%1 !^([^/]*)/.*::\1
RewriteRule ^(.*)$ /%1/$1 [L]