skip to Main Content

I have a site where the frontend is on the main domain and the backend is on a subdomain whose document root is a subfolder of the main domain’s document root.

I have added this:

 <IfModule mod_negotiation.c>
   Options -MultiViews
 </IfModule>

 <IfModule mod_rewrite.c>
   RewriteEngine On
   RewriteBase /
   RewriteRule ^index.html$ - [L]
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule . /index.html [L]
 </IfModule>

to the .htaccess file for the main domain because it was giving a 404 error for refreshes and direct access. The problem is that adding that config results in a 500 error on my backend. How can I solve this?

2

Answers


  1. Chosen as BEST ANSWER

    So it turns out I only needed to add one line to exclude the affected subdomain.

    RewriteCond %{HTTP_HOST} !example. [NC]
    

    That did the trick.


  2. You shouldn’t necessarily need to do anything with regards to the subdomain, depending on the type of requests you are making (which you’ve not stated).

    However, you can disable mod_rewrite for the subdomain by creating an additional .htaccess file in the root of the subdomain (ie. in the subfolder off the main domain’s document root) and place the following:

    # /subfolder/.htaccess (subdomain)
    RewriteEngine Off
    

    .htaccess files are inherited along the filesystem path, so the .htaccess file in the root of the main domain will certainly be processed when accessing the subdomain, except that the conditions (RewriteCond directives) should already exclude any requests for actual files/directories.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search