Sudomain自动重定向到https

时间:2018-01-30 08:59:01

标签: php laravel .htaccess

我的主域名为https://example.com。 我想使用没有HTTPS的子域名,http://hello.example.com,但问题是它会自动重定向到HTTPS。我该如何避免?

这是我当前的 .htaccess 结构:

             选项-MultiViews     

RewriteEngine On

# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 


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

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

2 个答案:

答案 0 :(得分:1)

您可以使用中间件进行此操作。 例如:

namespace App\Http\Middleware;
use Closure;
class HttpsProtocol {
    public function handle($request, Closure $next)
    {
            if (!$request->secure() && env('APP_ENV') === 'prod' AND [your chek url without subdomain]) {
                return redirect()->secure($request->getRequestUri()); //with https
            }

            return $next($request); 
    }
}

更改[your chek url without subdomain]

在Kernel.php中添加设置规则:

protected $middleware = [
    ...........

    // append HTTPS middleware 
    'App\Http\Middleware\HttpsProtocol'       

];

答案 1 :(得分:0)

<强>更新
或者,您可以添加以下代码:(我认为它更好

glob_var=class1(input)

fo_2替换为您的域名,并在RewriteCond %{HTTP_HOST} ^example\.com [NC]

之后添加此代码

example

相关问题