skip to Main Content

Here is a scenario of what I am trying to do.

Folder A has folders B and C.
Folder B has D, E and index.html.
Folder C has index.html

I declared folder B as my DocumentRoot. Declared an Alias for Folder C to point it to /A/C. I want apache to serve index.html in B for any requests coming in to B (/B/D or /B/E or /B/** should return /B/index.html)

Here is the sample virtual host config

<VirtualHost *:8080>
...
DocumentRoot "/usr/local/var/www/A/B" 
Alias "/C" "/usr/local/var/www/A/C" 
<Directory "/usr/local/var/www/A"> 
....
</Directory> 

RewriteEngine On 
RewriteCond %{ENV:REDIRECT_STATUS} !200 
RewriteRule ^/B/.+ /B/ [PT] 
....
</VirtualHost>

With this configuration, I am running in to redirect loop.

2

Answers


  1. the original request path,"/test/c/1", will match with "^/test/[abc].+$", matched successfully, so the request path change from "test/c/1" to "/test/". but due to the PT flag, cause the "/test/" routed back as if "/test/" is a newly come in, so "/test/" will match with "^/test/[abc].+$" again, but this time match failed, so you got 404.

    change the flag from PT to L, the behavior is while the original request path,"/test/c/1", match with "^/test/[abc].+$" successfully, the redirected path "/path" will be the final path. apache get the resource related "/test/" and response to the client.

    Login or Signup to reply.
  2. You may try this rule:

    RewriteEngine On 
    
    RewriteCond %{ENV:REDIRECT_STATUS} !200 
    RewriteRule ^/?B/(?!index.html$) /B/index.html [L,NC] 
    

    Then:

    1. Restart your Apache
    2. Test in a new browser or completely clear your browser cache
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search