I can’t work with Uri(routes) using virtual hosts

Asked

Viewed 161 times

1

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

site.com

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

127.0.0.1 site.com

And I made a setup in apache to access my site on 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 cannot access my routes using the virtual apache host example:

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

Anyway I can’t access any route(Uri), how can I solve this ?

I have a folder with several projects I made a . htaccess in it to not let anyone see my directory structure that way:

.htaccess Folder "Project":

Options -Indexes
IndexIgnore *

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

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]

See what my directory structure looks like:

projeto
   .htaccess
   site.com
       public_html
           .htaccess

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

  • 1

    how’s your file .htaccess ? Ask him the question too.

  • I edited the question put as this my file . htacces, and also put my directory structure.

  • 1

    Inside the directory site.com has the directory public_html?

  • Have yes I’m sorry, I’ll edit the question again, but I’ve changed the directory structure.

  • check the access permissions of directories

  • error when you access Urls?

  • Yes gives an error: 404 Not Found, the funny thing is that I did the same thing in windows and gave no error, I will send to folder permissions...

  • -rwxr-Xr-x 1 dev dev 313 Sep 14 12:11 . htaccess, all other files including my folders are with that same permission there.

Show 3 more comments

2 answers

2


What was happening is that I didn’t allow the file. htaccess in the public_html directory override, so I added some settings to 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>

The way it was before it’s like the . htaccess file doesn’t even exist.

1

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

Update

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

RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
  • I have disabled and failed.

  • But I did it here and it worked: site.com/index.php/v1.0/usuarios , because it works like this ? has how to get this index.php from the url ?

  • I want to access this way: site.com/v1.0/users

  • I’ll update the answer, I’m on mobile rs.

  • There’s something strange I tried to change mine. htaccess from the public_html folder I left as your did not work, I traded for several others I found on the internet and did not work, I put.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.