0

As an example, I am accessing project foo at https://localhost/projects/foo/dev/.

I'd like to rewrite the URL so that https://localhost/projects/foo/ points to projects/foo/dev/ in my DocumentRoot folder

This should not be an HTTP 3xx redirect. Furthermore dev1, dev2, and so on should not be accessible (unless there are directories inside of dev with those names but that's unlikely). Of course the rest of the path as well as query strings and fragments need to retained, for example:

projects/foo/dev/assets/js/jquery.min.js -> https://localhost/projects/foo/assets/js/jquery.min.js

This is my directory structure in my DocumentRoot folder:

  • projects/
    • foo/
      • dev/
      • dev1/
      • dev2/
      • dev3/
    • bar/
      • dev/
      • dev1/
      • dev2/
    • and so on...

I've tried the answer posted in this question but it isn't taking effect even after restarting Apache.

I've also tried this which seems correct but is giving me HTTP 500 with some infinite redirects error in error.log:

RewriteEngine on
RewriteRule ^(.*)$ src/$1 [L,QSA]

I only have access inside each project directory (e.g. foo and bar) and the parent directory may not be called projects on other machines. Therefore this needs to be done within htaccess files and not httpd.conf.

Community
  • 1
  • 1
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156

1 Answers1

0

You can use in your projects/.htaccess:

RewriteEngine on
RewriteCond $2 !^dev/ [NC]
RewriteRule ^(foo|bar)/(.*)$ $1/dev/$2 [NC,L]

Or for each directory in projects/ (not only fooand bar):

RewriteEngine on
RewriteCond $2 !^dev/ [NC]
RewriteRule ^([^/]+)/(.*)$ $1/dev/$2 [L]
Croises
  • 18,570
  • 4
  • 30
  • 47