regex.htaccessroutescpaneladdon-domain

Redirect all requests to index.php except subdomains


I'm using AltoRouter: (http://altorouter.com/) and I modified .htaccess as suggested in the instalation to:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

This is so that index.php can handle all the requests. My problem is that I am using addon domains in cpanel and I am having internal server errors when I try to access one of the domains associated with the addon domain.

Example: My main domain is mainsite.com.

Then I have several sites:

site1.com that cpanel automatically associates with site1.mainsite.com and creates a folder mainsite.com/site1.com. So if I access site1.com I would see in browser site1.com but the content delivered would be the one inside the mainsite.com/site.com folder.

This works if I don't use the .htaccess rule but I need it for routing. If I have that rule I get internal server errors everytime I access site1.com (I assume that it's a conflict between cpanel rules and .htaccess).

How can I modify the rule so that it only affects maindomain and not subdomains? I am assuming that by doing this there would be no conflict and my problem would be solved.

I am really bad at .htaccess and regex but I am willing to learn if needed. I would still appreciate if you could point me to the right direction. (both in the idea and in good websites that can help me understanding this)


Solution

  • How can I modify the rule so that it only affects maindomain and not subdomains?

    You can add a new condition based on host name:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^(?:www\.)?mainsite\.com$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule . index.php [L]