How can .htaccess be utilized to redirect all subdomains to the main domain in PHP?
To redirect all subdomains to the main domain using .htaccess in PHP, you can add a RewriteCond that checks if the request is not for the main domain and then use a RewriteRule to redirect all subdomains to the main domain.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^maindomain\.com$ [NC]
RewriteRule ^(.*)$ http://maindomain.com/$1 [L,R=301]