Htaccess redirect if folder exists

I am trying to redirect the user if a folder is set but I have no luck so far.

Below is my htaccess file.

RewriteEngine On
RewriteBase /enc/project/
# If the setup directory exists in the document root...
RewriteCond %{DOCUMENT_ROOT}/install -d
# ...and you're not in isntall..
RewriteCond %{REQUEST_URI} !(install) [NC]
# ...redirect to setup - with a 302 (temporary redirect) to make sure the browser won't cache the redirect.
RewriteRule ^(.*) /install [L,redirect=302]
# ...rest of htaccess for codeigniter
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

      

The codeigniter project is in /enc/project/

on my server, so RewriteBase.

Project Structure is

htdocs/enc/project/
|-- application/
|   |-- project
|
|-- system/
|   |-- project
|
|-- install/
|   |-- test/
|   |   |-- test_main.php
|   |   
|   |-- index.php
|
|-- htaccess

      

+3


source to share


2 answers


Try these rules



RewriteEngine On
RewriteBase /enc/project/

# If the setup directory exists in the document root...
RewriteCond %{DOCUMENT_ROOT}/enc/project/install -d
# ...and you're not in isntall..
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# ...redirect to setup - with a 302 (temporary redirect) to make sure the browser won't cache the redirect.
RewriteRule !^install/ install/ [L,NC,R=302]

# ...rest of htaccess for codeigniter
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

      

0


source


This is one way of writing:



RewriteEngine On
RewriteBase /enc/project/
# If the setup directory exists in the document root...
RewriteCond %{DOCUMENT_ROOT}/enc/project/install -d
# ...and you're not in isntall..
RewriteCond %{REQUEST_URI} !(install) [NC]
# ...redirect to setup - with a 302 (temporary redirect) to make sure the browser won't cache the redirect.
RewriteRule ^(.*) /enc/project/install/ [L,redirect=302]
# ...rest of htaccess for codeigniter
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

      

+1


source







All Articles