1

I have a local set up like this:

local.com/test/folder1/

How can I remove the 'test' directory from the URL but still include 'folder1' through .htaccess? like this:

local.com/folder1/

any help would be appreciated.

1 Answer 1

1

You can use this rule in site root .htaccess:

RewriteEngine On # add a trailing slash if test/$1 is a directory RewriteCond %{DOCUMENT_ROOT}/test/$1 -d RewriteRule ^(.*[^/])$ %{REQUEST_URI}/ [L,R=301,NE] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(?!test/)(.*)$ test/$1 [L,NC] 

(?!test/) is negative lookahead to skip rewrite when request is already starting with /test/

Sign up to request clarification or add additional context in comments.

2 Comments

cool, thanks. When I type in local.com/folder1/ it works great but when i type in: local.com/folder1 it goes to local.com/test/folder1/ anyway to prevent that from happening?
One last question. I have local.com/test2/ as a directory now it is saying it is 404 not found. How can I only apply the rules you wrote to ONLY directory 'test'??

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.