【问题标题】:Laravel Routing To subdomainLaravel 路由到子域
【发布时间】:2020-01-04 12:12:03
【问题描述】:

我正在使用 Laravel 5.7。目前所有路线都经过Api.phpweb.phpwebsite.php。在应用程序的实际版本中,有一个指向website.php 的子域是[anything].websiteaddress.com,而域www.websiteaddress.com 是指向web.php。在本地环境中,如何使用localhost:8000 访问子域。我尝试使用[anything].websiteaddress.com,它不起作用。访问子域的正确方法是什么?

【问题讨论】:

    标签: php laravel laravel-routing


    【解决方案1】:

    您可以使用http://lvh.me:8000

    lvh.me 是一项免费服务,可将所有子域自行解析为localhost

    没有什么可安装或运行的。如果您想测试example 子域,您只需转到http://example.lvh.me:8000 即可。

    它甚至可以在没有子域的情况下工作。例如,如果您的开发盒上有一个在localhost:8000 运行的应用程序,您可以转到lvh.me:8000 来加载它。

    您也可以尝试http://vcap.me:8000http://localtest.me:8000,它们都解析为127.0.0.1localhost

    【讨论】:

      【解决方案2】:

      1.在Web服务器中配置 httpd.conf 创建虚拟主机 ip 或命名您想要的名称

      <VirtualHost *:80>
      
       ServerName website.com
      
       ServerAlias *.website.com
      
      </VirtualHost>
      

      2.route配置like

      Route::group(array('domain' => '{account}.website.com'), function() {
      
          Route::get('/', function($account, $id) {
              // ...
              return Redirect::to('https://www.website.com'.'/'.$account);
          });
      
      });
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-03-01
        • 2016-09-18
        • 2016-09-25
        • 2015-09-10
        • 1970-01-01
        • 2021-11-17
        • 2017-07-18
        • 2017-11-17
        相关资源
        最近更新 更多