Problem with controllers on the live server

I have live server on apache. And it should be working when I go to the site www.example.com/sitename. Unfortunately only the home page works.
To create links I use:

<?= Html::a('logowanie', '/site/login'); ?>

But there is problem with go to controller becouse link refers to www.example.com/site/login and this not working. It shows: 404 Not Found.
On localhost everything worked fine. Any ideas how to fix it?

Is this a new application that you have created and deployed?

If you have not yet done so you will likely want to configure “Pretty URL’s” as per this guide (it’s not on by default):

If you have not done the above then the url for your login page will likely be this which is why your link does not work:
www.example.com/index.php?r=site/login

You can call that url and see if you stop getting the 404 not found response and your login page displays.

It’s possible also that your Apache web server does not have feature “mod_rewrite” enabled or it is not configured correctly. Your local development environment may have this enabled which is why it has always worked up until you deployed your application onto the live web server - see here for further help.