You are not logged in.

#1 2018-04-25 13:26:03

msalerno
Member
Registered: 2014-08-15
Posts: 32

Apache 2.4 and mod_rewrite

Situation:  I have to serve up some webpages but I can't modify the content.  The content needs to be protected with a username and password and for that I'm using apache mod_digest over http (it's an internal site).

For tracking purposes outside of my control, I need to add the %REMOTE_USER name to the URI and then ignore it.

For example:

  1. Browse to test.com

  2. Get prompted for username and password (this is working fine)

  3. Login successfully as user guest

  4. Redirected to: http://test.com/guest/

  5. All of the following calls get the same rules:  http://test.com/img1.jpg should be written as http://test.com/guest/img1.jpg

  6. All of these user URIs should map to the same Location/DocumentRoot:

I'm still trying to get the configuration right. The only examples I can find do the inverse of what I need, they keep the URI the same but rewrite the directory location. I put the following rewrite rule in place, It does the most of what I need it to do, but at least it's a starting point.  It's still rewriting the internal directory.

RewriteEngine On
RewriteCond %{LA-U:REMOTE_USER} ^[a-z].*
RewriteCond %{REQUEST_URI} !/%{LA-U:REMOTE_USER}/(.+)$
RewriteRule ^(.*)$ /%{REMOTE_USER}/%1 [R]

Any help would be greatly appreciated.

Thanks

Last edited by msalerno (2018-04-25 13:32:03)

Offline

#2 2018-04-25 13:49:53

msalerno
Member
Registered: 2014-08-15
Posts: 32

Re: Apache 2.4 and mod_rewrite

Unfortunately, the rules I pasted above cause too many redirects.  Still working on a solution.

Offline

#3 2018-04-25 18:36:11

msalerno
Member
Registered: 2014-08-15
Posts: 32

Re: Apache 2.4 and mod_rewrite

Solution:

<Server>
AliasMatch "^/users/.*" "/usr/local/apache2/htdocs/"
..
<Directory "/usr/local/apache2/htdocs">
    AuthType Basic
    AuthName "Authentication Required"
    AuthUserFile "/usr/local/apache2/Basic_pw"

    Require valid-user

    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/users/(.+)$
    RewriteRule ^(.*)$ /users/%{REMOTE_USER}/$1 [R]

...

I was making it way too complicated

Offline

#4 2018-04-25 19:10:47

V1del
Forum Moderator
Registered: 2012-10-16
Posts: 21,672

Re: Apache 2.4 and mod_rewrite

Glad to see you've found a solution, please mark the topic as such by prepending [SOLVED] or similar to the title in your first post.

Offline

Board footer

Powered by FluxBB