2

I set up .htaccess file to redirect to the _install folder if the app is just downloaded.

The problem I'm having is if the App was uploaded to a folder other than the root folder, the redirection break. It tries to go to the root folder

RewriteEngine on
#allow installation
RewriteCond %{REQUEST_URI} !^/_install

#redirect to _install if vendor does not exist
RewriteCond %{DOCUMENT_ROOT}/vendor !-d 
RewriteRule ^(.*) /_install [L,redirect=302]

#start application if vendor exists
#allow installation to continue
RewriteCond %{REQUEST_URI} !^/_install
RewriteCond %{DOCUMENT_ROOT}/vendor -d 
RewriteRule ^(.*) public/$1 [L]

so if the App is in the folder /project it redirects to /_install instead of /project/_install.

How do I make sure no matter what folder the App is, it will take everything from that folder?

Katerpiler
  • 119
  • 8
  • Well you can hardly expect this to be “flexible” in this regard, if you are checking absolute paths using `%{DOCUMENT_ROOT}`. – 04FS Jan 16 '20 at 08:35

1 Answers1

1

You can use it like this:

RewriteEngine on

# Determine the RewriteBase automatically/dynamically in env variable BASE
RewriteCond $0#%{REQUEST_URI} ^([^#]*)#(.*)\1$
RewriteRule ^.*$ - [E=BASE:%2]

#allow installation
RewriteCond %{REQUEST_URI} !/_install [NC]
#redirect to _install if vendor does not exist
RewriteCond %{DOCUMENT_ROOT}%{ENV:BASE}vendor !-d 
RewriteRule ^ %{ENV:BASE}_install [L,R=302]

#start application if vendor exists
#allow installation to continue
RewriteCond %{REQUEST_URI} !/_install
RewriteCond %{DOCUMENT_ROOT}%{ENV:BASE}vendor -d 
RewriteRule ^(.*) public/$1 [L]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • 1
    Thanks. This work perfectly! Where do I learn more about this? Is there a documentation on this? – Katerpiler Jan 16 '20 at 14:46
  • 1
    Check this answer of mine https://stackoverflow.com/a/21063276/548225 I have provided detailed explanation there. – anubhava Jan 16 '20 at 15:18