Laravel宅基地动态映射
Laravel Homestead dynamic mapping
我刚刚发现 Laravel Homestead 允许动态域映射。在 this tutorial 中,作者这样描述他的映射:
sites:
- map: '~^(?<project>.+)\.app$'
to: /home/vagrant/Code/$project/public
我想自动映射所有 .dev 域,而且我使用的是实际的域文件夹名称,所以我在代码段中对其进行了更改并稍微简化了它。我得到了什么:
sites:
- map: ~(?<project>.+)
to: /home/vagrant/www/$project/public
它工作得很好,但我很好奇它是否可以进一步简化。我试过这个,但它不起作用:
sites:
- map: ~.+
to: /home/vagrant/www/$0/public
这也不行:
sites:
- map: ~(.+)
to: /home/vagrant/www/$1/public
我想更好地理解这种语法。
在这里使用命名捕获是最安全的方法。根据 Nginx documentation:
A named regular expression capture can be used later as a variable
...
The captures can also be used in digital form:
server {
server_name ~^(www\.)?(.+)$;
location / {
root /sites/;
}
}
However, such usage should be limited to simple cases (like the above), since the digital references can easily be overwritten.
我刚刚发现 Laravel Homestead 允许动态域映射。在 this tutorial 中,作者这样描述他的映射:
sites:
- map: '~^(?<project>.+)\.app$'
to: /home/vagrant/Code/$project/public
我想自动映射所有 .dev 域,而且我使用的是实际的域文件夹名称,所以我在代码段中对其进行了更改并稍微简化了它。我得到了什么:
sites:
- map: ~(?<project>.+)
to: /home/vagrant/www/$project/public
它工作得很好,但我很好奇它是否可以进一步简化。我试过这个,但它不起作用:
sites:
- map: ~.+
to: /home/vagrant/www/$0/public
这也不行:
sites:
- map: ~(.+)
to: /home/vagrant/www/$1/public
我想更好地理解这种语法。
在这里使用命名捕获是最安全的方法。根据 Nginx documentation:
A named regular expression capture can be used later as a variable
...
The captures can also be used in digital form:
server {
server_name ~^(www\.)?(.+)$;
location / {
root /sites/;
}
}
However, such usage should be limited to simple cases (like the above), since the digital references can easily be overwritten.