I would like to use a directory ___test
like /___test/subdirectory1/
and have some contents, but never show this path in the url. Instead I would like the url /demo/subdirectory1
or say, /demo/subdirectory1/images/image.jpg
to point to /___test/subdirectory1/images/image.jpg
and the url on the browser to stay like: /demo/subdirectory1/images/image.jpg
. Actually replacing ___test
with demo
What I have tried with various problems although it looks like it works sometimes is:
RewriteRule ^demo/subdirectory1(.*) ___test/subdirectory1/$1
The above works only on: demo/subdirectory1
or demo/subdirectory1/
(with existing content example an index.html inside /___test/subdirectory1/
) but not on demo/subdirectory1/somethingmore...
although the content is there in this case as well, unfortunately it shows the real directory path in the url.
Additionally, I am using the following to through 404 to anything starting from /___test
in the url:
RewriteCond %{THE_REQUEST} ^GET\ /___test/
RewriteRule ^___test/(.*) - [R=404,L,NC]
It works, but when I add this, then the previous goes to 404 too, unfortunately (again). But most important for me is to make the first part right, even if I never make the second work.
Any help really appreciated. Thanks.
Edit 1:
I have also tried adding the following inside an /___test/subdirectory1/.htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteBase /___test/subdirectory1
no success.
Edit 2: Although it doesn't work well, the best I came up with so far with the help of Jon Lin is the following:
RewriteCond %{REQUEST_URI} ^/demo/subdirectory1(.*)
RewriteCond %{DOCUMENT_ROOT}/___test/subdirectory1/%1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/___test/subdirectory1/%1 -d
RewriteRule ^ /___test/subdirectory1/%1 [L]
/demo/subdirectory1
<- OK
/demo/subdirectory1/
<- OK
/demo/subdirectory1/subdirectory2
<- Exposes real path
/demo/subdirectory1/subdirectory2/
<- OK
/demo/subdirectory1/subdirectory2/subdirectory3
<- Exposes real path
/demo/subdirectory1/subdirectory2/subdirectory3/
<- OK
As you can see, whatever is deeper level than subdirectory1
has problem. I just cannot understand why. Testing this on a clean .htaccess file existing in the root of the site (no other deeper) on a linux apache.