John John - 3 days ago 5
Apache Configuration Question

.htaccess ignore directory but include subdirectory with the same name

I have a directory called 'success-centers' (i dont want to go here)

I have a subdirectory called 'portal-pages/success-centers'

How do I ignore the first one but have my URL be:

local.com/success-centers/ OR local.com/success-centers/index.html through .htaccess?

this is my current htaccess file in the ROOT. it works fine but when I go to local.com/success-centers/ it goes to the directory that I do NOT want to go to.

Any help would be great. thanks.

RewriteEngine On

# add a trailing slash if portal-pages/$1 is a directory
RewriteCond %{DOCUMENT_ROOT}/portal-pages/$1 -d
RewriteRule ^(.*[^/])$ %{REQUEST_URI}/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(?!portal-pages/)(.*)$ portal-pages/$1 [L,NC]

Answer

Have it like this:

RewriteEngine On

# add a trailing slash if portal-pages/$1 is a directory
RewriteCond %{DOCUMENT_ROOT}/portal-pages/$1 -d
RewriteRule ^(.*[^/])$ %{REQUEST_URI}/ [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(?!portal-pages/)(.*)$ portal-pages/$1 [L,NC]

There is no need to check for -f or -d as you want portal-pages/success-centers/ when URI in browser is /success-centers/.

Comments