Search code examples
phplaravellaravel-7

Laravel Redirecting multiple pointed URL's


I have a live site that is going to have other URL's pointed to it with SSL. I can't seem to figure out how to have laravel redirect all incoming url traffic to its main url. If i use one of the new URL's it shows up as that url which is fine but it doesn't add SSL REDIRECT unless i actively add the Https to it. I'd prefer it to just switch over to the original APP_URL once the site responds to the URL request.

Laravel Framework 7.22.4


Solution

  • I actually found the solution:

    writing a rewrite to all traffic in the .htaccess file found in the public folder. now all my other domains i have pointed to the site have redirected to the site correctly!

    <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]
    
    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
    
     RewriteEngine On
     RewriteCond %{SERVER_PORT} 80
     RewriteRule ^(.*)$ https://{{ADD_URL_HERE}} [R,L]