更新时间:2023-02-24 09:38:44
在本地测试时,我会做两件事之一.
When testing locally I do one of two things.
使用以下内容在公共目录下创建一个新的 .htaccess.
Create a new .htaccess below the public directory with the following.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
创建一个新的虚拟主机.使用 WAMP,您可以导航到 C:\wamp\bin\apache\YOUR APACHE VERSION\conf\extra
并找到您的 httpd-vhosts.conf
文件,在那里您可以请参阅示例虚拟主机.这是我的一个:
Create a new virtual host. With WAMP you can navigate to C:\wamp\bin\apache\YOUR APACHE VERSION\conf\extra
and find your httpd-vhosts.conf
file, in there you can see example virtual hosts. Here's one of mine:
<VirtualHost *:80>
DocumentRoot "c:/wamp/www/laravel/public"
ServerName laravel.dev
ServerAlias www.laravel.dev
</VirtualHost>
确保包含您的 vhosts 配置文件.打开你的 httpd.conf
文件并搜索 vhosts
文件,如果它被注释掉,取消注释包含行.然后我打开 CLI 并输入 notepad "C:\windows\system32\drivers\etc\hosts"
这会打开你的主机文件.在提到 localhost
的项目下面放置您的新主机.这是一个例子.
Make sure that your vhosts configuration file is being included. Open up your httpd.conf
file and search for the vhosts
file, uncomment the include line if it's commented out. Then I open the CLI and enter notepad "C:\windows\system32\drivers\etc\hosts"
which opens up your hosts file. Underneath the item that mentions localhost
place your new host. Here's an example.
127.0.0.1 laravel.dev
确保您重新启动 Apache 和宾果游戏,您应该能够导航到 http://laravel.dev
并且您不会有任何烦人的公共目录.这就是我实现它的方式,因为我更喜欢看起来更好看的虚拟主机,而不是冗长的 localhost
URL.
Make sure you restart Apache and bingo, you should be able to navigate to http://laravel.dev
and you won't have any annoying public directory. This is how I achieve it, as I prefer the nicer looking virtual host rather then a long winded localhost
URL.
希望这会有所帮助.