How do I force HTTPS in Taskify?

How do I force HTTPS in Taskify?

Answer: Configure HTTPS enforcement in your AppServiceProvider or server configuration to ensure all traffic is encrypted.

Laravel Configuration:

In your AppServiceProvider.php:

use Illuminate\Support\Facades\URL;

public function boot()
{
    if (config('app.env') === 'production') {
        URL::forceScheme('https');
    }
}

Server-Level Configuration:

Apache (.htaccess):

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Nginx:

server {
    listen 80;
    server_name your-domain.com;
    return 301 https://$server_name$request_uri;
}

server {
    listen 443 ssl;
    server_name your-domain.com;
    # SSL configuration here
}

Environment Configuration:

Set these in your .env file:

APP_URL=https://your-domain.com
FORCE_HTTPS=true

Additional Security Headers:

Add security headers to your application:

// In AppServiceProvider boot method
$response->headers->set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains');
$response->headers->set('X-Content-Type-Options', 'nosniff');
$response->headers->set('X-Frame-Options', 'DENY');
$response->headers->set('X-XSS-Protection', '1; mode=block');

Verification:

After implementing HTTPS enforcement:

  1. Test HTTP to HTTPS redirection
  2. Verify SSL certificate is valid
  3. Check for mixed content warnings
  4. Test all application functionality