0

I'm currently converting an old website to use Symfony 4 and the site uses the LiveZilla live chat app.

LiveZilla lives in a subfolder of the site, and is accessed directly using URLs under somesite.com/livezilla. I can't currently access it of course, because I haven't configured a route for this folder. So Symfony decides that this will be a 404.

LiveZilla is essentially a completely separate app living in its own folder here. It isn't dependent on the website hosting it. Is there a way to tell Symfony to ignore certain paths so that code like this can be executed without interference?

I have a sneaking feeling that I need to adjust the way I am looking at this as I can't find anything obvious in the Symfony docs about this, and the framework is pretty well thought out. The best I have come up with so far is hacking public/.htaccess, but it feels wrong somehow...

tereško
  • 58,060
  • 25
  • 98
  • 150
MickDG
  • 3
  • 2
  • If the two websites are independents, you should really not put your old website inside your Symfony app. Instead, deploy your apps on two different locations and configure your web server to do the job. For example, if you're running nginx, you could add a `location` block inside your main website `location` and point it to your old website – Manu Nov 08 '19 at 15:54
  • Thanks Manu, interesting thought. LiveZilla recommends that their software is installed in a subdirectory of the site it is being used on. Worst case scenario, I guess it could be installed on (e.g.) a subdomain and served from elsewhere though. I'll try that if I really can't find another way of doing this. – MickDG Nov 08 '19 at 15:58
  • As i maintain that your LiveZilla app should live outside your SF app (why would a third-party independent app should be part of your sources ?), if you want to do it anyway, you could get it working by putting your LiveZilla app in the `public/` folder and yes, as you mentioned, either add a rule to your SF app `.htaccess` (eg. `RewriteRule ^livezilla/(.*)$ livezilla/$1 [L]`) or reconfigure your vhost properly. I think the second option should be preferred. – Manu Nov 08 '19 at 16:08
  • Sounds like a plan! I'll try that, thanks Manu – MickDG Nov 08 '19 at 16:37
  • Implemented the suggestion below, but also added the LiveZilla files to a separate repo. All good now, thanks for the input :) – MickDG Nov 09 '19 at 11:42

1 Answers1

0

Your .htaccess file should allow requests directly to existing files, but not directories. See this rule:

# If the requested filename exists, simply serve it.
# We only want to let Apache serve files and not directories.
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

This means you should be able to access somesite.com/livezilla/index.php but a request to somesite.com/livezilla will redirect to the symfony front controller. So try changing your links to point to actual files within the sub-directory.

There is also nothing wrong with editing the .htaccess file to suit your needs. You just need a condition that checks if the request is to the sub-directory and if so use the same RewriteRule ^ - [L] as above to allow that request to continue.

The following should work if placed after the above rule (reference):

RewriteCond %{REQUEST_URI} ^/livezilla/ 
RewriteRule ^ - [L]

Or this may be better, place this rule immediately after the line RewriteEngine On(reference)

RewriteRule ^(livezilla) - [L]

The [L] flag means the rule will be the last one used for the request.

Arleigh Hix
  • 9,990
  • 1
  • 14
  • 31
  • Many thanks Arleigh, your suggestions work perfectly/have given me the way forward I was looking for (completely missed the fact that you can add physical files too. Doh!) – MickDG Nov 09 '19 at 11:39