.htaccess - Apache alias/rewrite to a subdirectory without redirecting -
as example, accessing project foo
@ https://localhost/projects/foo/dev/
.
i'd rewrite url https://localhost/projects/foo/
points projects/foo/dev/
in documentroot folder
this should not http 3xx redirect. furthermore dev1
, dev2
, , on should not accessible (unless there directories inside of dev
names that's unlikely). of course rest of path query strings , fragments need retained, example:
projects/foo/dev/assets/js/jquery.min.js -> https://localhost/projects/foo/assets/js/jquery.min.js
this directory structure in documentroot folder:
- projects/
- foo/
- dev/
- dev1/
- dev2/
- dev3/
- bar/
- dev/
- dev1/
- dev2/
- and on...
- foo/
i've tried answer posted in this question isn't taking effect after restarting apache.
i've tried seems correct giving me http 500 infinite redirects error in error.log
:
rewriteengine on rewriterule ^(.*)$ src/$1 [l,qsa]
i have access inside each project directory (e.g. foo
, bar
) , parent directory may not called projects
on other machines. therefore needs done within htaccess files , not httpd.conf.
you can use in projects/.htaccess
:
rewriteengine on rewritecond $2 !^dev/ [nc] rewriterule ^(foo|bar)/(.*)$ $1/dev/$2 [nc,l]
or each directory in projects/
(not foo
and bar
):
rewriteengine on rewritecond $2 !^dev/ [nc] rewriterule ^([^/]+)/(.*)$ $1/dev/$2 [l]
Comments
Post a Comment