I can not work with uri (routes) using virtual hosts

1

I created a virtual host using apache, the problem is that I can access the site in my localhost as follows:

site.com

To access my site in localhost this way I did the following in the / etc / hosts file:

127.0.0.1 site.com

And I made a configuration in apache to to access my site in localhost, the configuration is as follows:

<VirtualHost *:80>
    ServerAdmin [email protected]
    ServerName site.com
    ServerAlias www.site.com
    DocumentRoot /var/www/site.com/public_html
    ErrorLog ${APACHE_LOG_DIR}/error.log
    CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>

The problem is that I can not access my routes using the apache virtual host example:

site.com/usuarios
site.com/v1.0/usuarios

Finally, I can not access any route (uri), how can I resolve this?

I have a folder with several projects I made a .htaccess on it so I would not let anyone see my directory structure like this:

.htaccess "Project" folder:

Options -Indexes
IndexIgnore *

Now inside this project folder I have another folder that is called "site.com" which is the project that I can not access any uri, inside it I have a folder that is called "public_html" that has another file. htaccess and an index.php file, the .htaccess file looks like this:

RewriteEngine On

# Some hosts may require you to use the 'RewriteBase' directive.
# If you need to use the 'RewriteBase' directive, it should be the
# absolute physical path to the directory that contains this htaccess file.
#
# RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

Here's my directory structure:

projeto
   .htaccess
   site.com
       public_html
           .htaccess

I know that what I apply in a .htaccess in the higher folders is also applied to the subfolder, is there anything wrong with the .haccess that were created in these two folders? or is it my virtual host configuration that is incorrect?

    
asked by anonymous 15.09.2017 / 04:46

2 answers

2

What was happening is that I did not allow the .htaccess file in the public_html directory to override, so I added some settings on my apache virtual host to allow this, see the new virtual host configuration:

ServerName 127.0.1.1
<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerName site.com
        ServerAlias www.site.com
        DocumentRoot /var/www/site.com/public_html
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        #Foi necessario acresentar essas configuracoes
        #pois eu nao estava conseguindo acessar uris(rotas)
        #de todas as configuracoes a mais importante
        #e que resolvel meu problema foi a AllowOverride all
        <Directory /var/www/site.com/public_html/>
                Options Indexes FollowSymLinks MultiViews
                AllowOverride all
                Order allow,deny
                allow from all
                # Uncomment this directive is you want to see apache2's
                # default start page (in /apache2-default) when you go to /
                #RedirectMatch ^/$ /apache2-default/
        </Directory>
</VirtualHost>

As before, it's as if the .htaccess file did not even exist.

    
15.09.2017 / 15:12
1

The problem is in .htaccess of directory Projeto line IndexIgnore * disables directory listing.

Update

As informed by comments. Edit the .htaccess of the public_html directory and leave it that way, so I can edit the answer, explaining a certain part of the code.

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
    
15.09.2017 / 13:05