.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...

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 fooand bar):

rewriteengine on rewritecond $2 !^dev/ [nc] rewriterule ^([^/]+)/(.*)$ $1/dev/$2 [l] 

Comments

Popular posts from this blog

javascript - Chart.js (Radar Chart) different scaleLineColor for each scaleLine -

apache - Error with PHP mail(): Multiple or malformed newlines found in additional_header -

java - Android – MapFragment overlay button shadow, just like MyLocation button -