1

I have Craft public files set up within subdirectories of a primary domain’s web root.

public_html/ # default web root
public_html/example.com/public_html/ # Craft public files here

The following .htaccess rules allow for the public_html subdirectory to act as the new web root. This is the .htaccess within the first public_html directory.

RewriteEngine on

RewriteCond %{HTTP_HOST} ^example.com$
RewriteCond %{REQUEST_URI} !^/example.com/public_html/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example.com/public_html/$1

RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule ^(/)?$ example.com/public_html/index.php?p=$1 [QSA,L]

It works until I go to example.com/admin.

I can login and cp works, but the URL is http://example.com/example.com/public_html/admin/dashboard

I'd like to remove the subdirectories from the above admin URL for mere aesthetic reasons, but can’t seem to nail it down.

Note: When going directly to http://example.com/admin/dashboard, for example, the URL remains as is, but all the internal links have the subdirectories.

  • Are you using cpanel by chance? – RitterKnight Feb 16 '16 at 17:22
3

I have Craft public files set up within subdirectories of a primary domain’s web root.

The following .htaccess rules allow for the public_html subdirectory to act as the new web root.

Is there a reason you're doing it this way? The .htaccess you have is only rewriting the content, it's not actually setting the web root. You're basically asking Apache to serve content out of the root for your other domain. There's only a couple circumstances I can think of where you'd need to actually do that (mirroring a domain for example but that's not something you probably want to do here).

For that, you need to set Apache's DocumentRoot properly for your second domain.

It sounds like you have a CPanel based setup, where it's common for it to put add-on domains inside of the web root of the primary domain by default. I'm not sure how the document root got changed to the primary domain but you need to set the document root of the add-on domain to the proper place (in Cpanel it's usually the Modify Domain function).

What you type in depends on your path but it's probably set to just public_html now. You want public_html/example.com/public_html/.

That'll get you back to a properly functioning setup. Then just use Craft's default .htaccess file.

| improve this answer | |
  • I really appreciate this. There is a reason; but now I'm weighing whether or not it's worth it. Basically, I wanted to see if it was possible. If it were it'd help to keep the .gitignore file clean of all the server's default files below web root. :) Just laziness trying to find a solution. It is cpanel, but this is for the primary domain so I can't modify the domain. – Stephen Callender Feb 16 '16 at 18:35
  • 1
    Depending on what you're trying to do, some hosting companies allow tweaking of cpanel's defaults, then you can exercise more control. Worst case, get a vps from linode or droplet from digital ocean and do whatever you want including proper git deployment ;) – RitterKnight Feb 16 '16 at 18:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.