1

I'm rebuilding a website which needs to run Craft CMS as the main frontend and a bespoke CRM system at the same domain.

The file setup is basically

  • public_html
    • cms
    • crm

To make things a bit more complicated, certain parts of the CRM have to be publically accessible, so there are a few different URL structures that need to run from the CRM, and the rest from Craft. Also, the images/scripts are in the cms folder, so I need to get those to work without cms in the URL.

For the most part this is working lovely, but I can't get force /cms/ to be removed from the URL, so whilst the site works fine without it, it's live on 2 different URLs.

I have the with the following code:

<IfModule mod_rewrite.c>

    # Force the root to match slug of home page
    # This is the only way I can get the home page to
    # show on the root, as it's within a structure
    RewriteRule ^$ /__home__

    # Get rid of /cms (this doesn't work)
    RewriteRule ^cms/?(.+)$ /$1 [R=301]

    # Sort out frontend files
    RewriteCond %{REQUEST_URI} /assets/.*
    RewriteCond %{REQUEST_URI} !/assets/admin/.*
    RewriteCond %{REQUEST_URI} !/cms/.*
    RewriteCond %{REQUEST_URI} !/crm/web/.*
    RewriteRule ^(.*\.(gif|jpg|jpeg|bmp|svg|png|css|js|json|pdf|eot|woff|woff2|ttf|otf))$ /cms/$1 [QSA,L]

    # Sort out admin files
    RewriteCond %{REQUEST_URI} /assets/admin/.*
    RewriteCond %{REQUEST_URI} !/cms/.*
    RewriteCond %{REQUEST_URI} !/crm/web/.*
    RewriteRule ^(.*\.(gif|jpg|jpeg|bmp|svg|png|css|js|json|pdf|eot|woff|woff2|ttf|otf))$ /crm/web/$1 [QSA,L]

    # Send would-be 404 requests to Craft
    # Need to exclude any that should route to the CRM
    # Any that we exclude, we then need to route below
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} !^/(favicon\.ico|apple-touch-icon.*\.png)$ [NC]
    RewriteCond %{REQUEST_URI} !^/manager/?(.*)$ [NC]
    RewriteCond %{REQUEST_URI} !^/forms/(.+)$ [NC]
    RewriteCond %{REQUEST_URI} !^/partners/?(.*)$ [NC]
    RewriteCond %{REQUEST_URI} !^$ [NC]
    RewriteRule (.+) /cms/index.php/$1 [QSA,L]

    # CRM Admin
    RewriteCond %{REQUEST_URI} ^/manager/?(.*)$ [NC]
    RewriteRule ^manager/?(.*) /crm/web/app.php [QSA,L]

    # Quote Forms
    RewriteCond %{REQUEST_URI} ^/forms/(.+)$ [NC]
    RewriteRule ^forms/(.+) /crm/web/app.php [QSA,L]

    # Signup Forms
    RewriteCond %{REQUEST_URI} ^/partners/?(.*)$ [NC]
    RewriteRule ^partners/?(.*) /crm/web/app.php [QSA,L]

</IfModule>

So I'm fairly sure that the line RewriteRule ^cms/?(.+)$ /$1 [R=301] would work, but the default Craft logic is somehow preventing it - if I comment out the default craft section, then it removes cms from the URLs, but obviously nothing is routed through Craft, so 404s all round.

I'm completely stumped at this point, so any help would be appreciated!

1 Answer 1

1

I might be way off here, but if you are wanting to run Craft as your main front-end, could you not place the Craft index.php in the root of the site and then you CRM in a sub-folder of its own?

If you have all you CRM stuff in its own sub-folder, Craft should just ignore that folder as it physically exists. If you've got specific things you need to have in your .htaccess file for you CRM, you could have that .htaccess in the sub-folder, rather than the root. That way you can just have the standard Craft .htaccess file in the root of the site.

3
  • 1
    Interesting. It was set up the way it is as it's essentially two github repos, but you're right, that might make more sense. I'll give this a go, thanks.
    – Jammooka
    Commented Jun 20, 2017 at 15:42
  • 1
    This was the way to go - took a bit of reconfiguration, but far simpler outcome. Thanks!
    – Jammooka
    Commented Jun 21, 2017 at 12:17
  • Great stuff glad I could help :) Commented Jun 21, 2017 at 13:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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