ckaufman
ckaufman

Reputation: 1497

.htaccess rewrite subdirectory to parent directory

I have a page template that exists at a directory:

/users/

I would like to use the page template at this level, call it index.php for any other sub directories within this directory

/users/firstname-lastname/

Essentially using the next directory as a clean query string to dictate what is on the index.php page.

Thanks in advance for the help!

Upvotes: 0

Views: 1815

Answers (1)

anubhava
anubhava

Reputation: 785146

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:

Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /

RewriteCond %{DOCUMENT_ROOT}/$1/$2 -d   
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(users)/(.+)$ /$1/index.php [NC,L]

Upvotes: 2

Related Questions