Access specific folder project

Asked

Viewed 86 times

0

I have the following url

http://localhost/meuApp

Angled

My file . htaccess is like this:

RewriteEngine On
# If an existing asset or directory is requested go to it as it is
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI} -d
RewriteRule ^ - [L]

# If the requested resource doesn't exist, use index.html
RewriteRule ^ /meuApp/index.html

I would like that inside this directory I save the files inside a subfolder called: frontend

Thus remaining:

minhaApp
      |__ frontend

But kept calling it like this: localhost/meuApp

I tried using the code below, but it does redirect to the subdirectory and come back and that’s not what I want

RewriteEngine On
RewriteBase /meuApp

RewriteCond %{REQUEST_URI} !^/meuApp/frontend
RewriteCond %{REQUEST_URI} !^/meuApp/exclude-file1\.html$
RewriteCond %{REQUEST_URI} !^/meuApp/exclude-file2\.html$
RewriteCond %{REQUEST_URI} !^/meuApp/exclude-dir
RewriteRule (.*) frontend/$1 [R=302,L]
  • And there will be something that should be accessed outside the subfolder?

  • Only customers who will access the system

  • Yes but have static files and scripts outside the front-end folder accessible via URL? Business rules don’t matter yet, the question is about the behavior of urls

  • No. Files are all inside the frontend folder

  • Okay, I’m gonna repeat the question, because every time you answer, you make a different point... What this OUTSIDE frontend folder needs to be accessible via URL in some way or other folders?

  • No. There’s nothing outside the frontend folder. What you may have is the backend folder that will be in Nodejs, but you will not have files that will need to access via URL

Show 1 more comment

1 answer

1


Just don’t use RewriteCond before, just point everything to ./frontend directly and then in the next rule you write the "routes" of the Angular, so:

RewriteEngine On

# Redireciona tudo
RewriteRule ^ frontend/ [L]

# Se estiver dentro de frontend checa se o arquivo existe
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

# se for uma rota direciona para meuApp/index.html
RewriteRule ^ index.html [L]

This if its structure were outside:

./public_html
  └───.htaccess
  └───frontend
      ├───images
      └───index.html (do angular)

Note that you do not have the bars / in front, the path is relative, unless you want to configure from another point.

Must use the [L] for the current rule so that two rules do not mix. I have not tested, but in theory it is this, if it does not work you can create 2 . htaccess, like this:

./public_html
  ├───.htaccess
  └───frontend
      ├───images
      ├───.htaccess
      └───index.html (do angular)

Getting the htaccess of public_html so just (no more):

RewriteEngine On

RewriteRule ^ frontend/ [L]

And the . htaccess inside the frontend so:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

# se for uma rota direciona para index.html
RewriteRule ^ index.html [L]
  • And if I wanted to put more than one project inside that folder, but calling the different url: For example: http://192.168. 1.1/meuapp and http://192.168. 1.1/meuapp2, I could reuse . htaccess?

  • @adventistaam ai depends, both apps will use the same frontend?

  • In this case yes.. Both projects will use the same directory frontend

  • @adventistaam has no way to take advantage of the structure then, would have to do otherwise

  • Got it.. All right. Thanks for the solution anyway. Already helped a lot

Browser other questions tagged

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