Marley
Marley

Reputation: 61

How to I configure htaccess - if file is not found at root search a subfolder

What do I put in htaccess so that if a file is not found at root, go look for it in a subfolder? I would like for my customers to be able type in this url: https://mysite/CustomerX.php? but it resolve to https://mysite/LandingPages/CustomerX.php?

I don't want to redirect EVERYTHING away from root, only the files that aren't found there.

I have 600 customers, each with a custom landing page, so I need an automatic way for this to redirect. I do not actually want to put their 600 landing pages at the root so I am hoping for a way to redirect this. I'm pretty sure it's mod-rewrite but I can't figure out how to do the if-its-not-there part of it.

Upvotes: 1

Views: 44

Answers (1)

anubhava
anubhava

Reputation: 785156

You can keep this rule in root .htaccess:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/LandingPages/$1 -f
RewriteRule ^(.+)$ /LandingPages/$1 [L]

Upvotes: 1

Related Questions