Subfolder configuration in htaccess

Asked

Viewed 95 times

0

Well I have a lodging with the following structure:

index.html
.htaccess
app
site

Well, inside the app folder I have an application compiled in Angular 7.0 and inside the site folder I also have a site made in Angular 7.0.

Good for the Angular routing to work I have to do the following configuration on htaccess:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /index.html?path=$1 [NC,L,QSA]

But I don’t want to have to create a htaccess for each folder, I wanted to make all the settings in the htaccess that is at the root.

I tried to do it this way:

# Configurações do url
<IfModule mod_rewrite.c>
RewriteEngine On

# Angular APP
RewriteBase /app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /app/index.html?path=$1 [NC,L,QSA]

# Angular Site
RewriteBase /site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /site/index.html?path=$1 [NC,L,QSA]
</IfModule>

But the htaccess this only respecting the first configuration ( # Angular APP).

Is there any way to fix this?

1 answer

1


Is he not ignoring the folder? Try deleting the second option like this:

# Configurações do url
<IfModule mod_rewrite.c>
RewriteEngine On

# Angular APP
RewriteBase /app/
RewriteCond %{REQUEST_URI} !^/site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /app/index.html?path=$1 [NC,L,QSA]

# Angular Site
RewriteBase /site/
RewriteCond %{REQUEST_URI} !^/app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\.(?:css|js|map|jpe?g|gif|png)$ [NC]
RewriteRule ^(.*)$ /site/index.html?path=$1 [NC,L,QSA]
</IfModule>
  • It worked out, thank you.

  • For nothing, basically removed the URL that is not in use

Browser other questions tagged

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