简体   繁体   English

laravel 5.5-通配符子域不起作用

[英]laravel 5.5 - wildcard subdomain not working

I am upload my laravel app in the Apache shared hosting server and everything setup fine. 我将laravel应用程序上传到Apache共享托管服务器中,一切设置正常。 I have CNAME record set up * subdomain and point it to the public_html/ . 我已经设置了CNAME记录*子域,并将其指向public_html/ then I set this code in my routes/web.php : 然后我在我的routes/web.php设置此代码:

Route::domain('{subdomain}.example.com')->group(function () {
    Route::get('/', function ($subdomain) {
        Route::get('/profiles/sub/{subdomain}', 'ProfilesController@subDomain');
    });
});

which ProfilesController@subDomain is a function to process the parameter subdomain from the URL . 其中ProfilesController@subDomain是用于处理URL中的参数subdomain的函数。 But the result keep sending me to the main landing page. 但是结果一直将我发送到主登陆页面。 I notice there is this error: 我注意到有此错误:

Uncaught (in promise) DOMException: Only secure origins are allowed 未捕获(承诺)DOMException:仅允许安全来源

which I am not sure if it is something to do with any part. 我不确定这是否与任何部分有关。

How can I resolve this? 我该如何解决?

Update01 Update01

Following Ben's comment, I force SSL with the .htaccess below: 按照Ben的评论,我使用下面的.htaccess force SSL

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews -Indexes
    </IfModule>

    RewriteEngine On
    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} (.+)/$
    RewriteRule ^ %1 [L,R=301]


    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

<ifmodule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{HTTPS} !=on
 RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
</ifmodule>

It will force http to https . 它将http强制为https But whenever I test subdomain like xxx.example.com , Chrome will give a privacy error message, then change it back to: 但是,每当我测试xxx.example.com子域时,Chrome都会给出一条隐私错误消息,然后将其更改回: 在此处输入图片说明

and new error message: 和新的错误信息:

An SSL certificate error occurred when fetching the script. 提取脚本时发生SSL证书错误。

Just a reminder, I am trying to solve the wildcard subdomain issue here. 提醒一下,我正在尝试解决此处的通配符子域问题。 If all this SSL is not the real reason, we can ignore that. 如果不是所有这些SSL的真正原因,我们都可以忽略。

I think it should be 我认为应该

Route::domain('{subdomain}.example.com')->group(function () { 
    Route::get('/', 'ProfilesController@subDomain'); 
});

and in ProfilesController : 并在ProfilesController

public function subdomain($subdomain) {
//do something
}

AND as discussed, the order of routes is important, so if you have a route declared for '/' before this logic, it will always hit it first. 而且,正如讨论的那样,路由的顺序很重要,因此,如果在此逻辑之前有一个声明为'/'的路由,它将始终先命中它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM