I will redirect all non-www domains in my Laravel .htaccess to a www-domain , except subdomains and development domains (*.app).
I have an application with multiple domainnames, now I use a long list in my htaccess, but that's a bad way...
# bad way :(
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule (.*) https://www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^example1.com [NC]
RewriteRule (.*) https://www.example1.com/$1 [R=301,L]
# etc... a very long list...
How can i redirect all non-www-domains to a www-version:
You can use a single rule like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} !\.app$ [NC]
RewriteCond %{HTTP_HOST} !^[\w-]+\.[\w-]+\.(com|be|de|co\.uk)$ [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI{ [R=301,NE,L]
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.