I'm having HTTPS with my main domain ie https://example.com. And I want to use subdomain without HTTPS ie, http://hello.example.com but the problem is it automatically redirects to HTTPS. How do I avoid that?
This is my current .htaccess structure:
Options -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}]
UPDATE
Alternatively, You can add this code : (I think It's better one)
RewriteCond %{HTTP_HOST} ^example\.com [NC]
Replace example
with your domain name and Add this code after line 9
RewriteCond %{HTTP_HOST} !^([a-zA-Z0-9\-]+)\.example\.com
You can make this with a Middleware. For example:
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);
}
}
Change [your chek url without subdomain]
And adding setting the rule at Kernel.php:
protected $middleware = [
...........
// append HTTPS middleware
'App\Http\Middleware\HttpsProtocol'
];