You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Jon Forrest <jl...@berkeley.edu> on 2007/11/02 01:13:34 UTC
[users@httpd] Very Puzzling Question About mod_rewrite
(This is on Solaris 10-x86 with Apache 2.2.4)
When I give the URL
1) http://www-demo.cchem.berkeley.edu/username/public_html
everything works fine. However, for historical reasons,
I can't require that people give the "/public_html" at
the end of the URL. In other words, I want users to
be able to enter
2) http://www-demo.cchem.berkeley.edu/username/
to see the same results as produced by URL #1 .
So, I decided to try mod_rewrite. I use the following
in the proper VirtualHost section of my httpd.conf file:
RewriteLogLevel 5
RewriteLog "/users/chemweb/apache2/logs/rewrite.log"
RewriteEngine on
RewriteRule ^(.+)$ $1/public_html/ [L]
This doesn't work. The client sees a "403 Forbidden" message.
The apache log says:
"Directory index forbidden by Options directive:
/users/chemweb/apache2/http-cchem/htdocs/username/public_html/"
I don't understand why I'm getting this message when
URL #1 above works.
The rewrite log shows the following (I added the #numbers):
#1 (2) init rewrite engine with requested uri /username/
#2 (3) applying pattern '^(.+)$' to uri '/username/'
#3 (2) rewrite '/username/' -> '/username//public_html/'
#4 (2) local path result: /username//public_html/
#5 (2) prefixed with document_root to
/users/chemweb/apache2/http-cchem/htdocs/username/public_html/
#6 (1) go-ahead with
/users/chemweb/apache2/http-cchem/htdocs/username/public_html/ [OK]
#7 (2) init rewrite engine with requested uri /username/index.html
#8 (3) applying pattern '^(.+)$' to uri '/username/index.html'
#9 (2) rewrite '/username/index.html' -> '/username/index.html/public_html/'
#10 (2) local path result: /username/index.html/public_html/
#11 (2) prefixed with document_root to
/users/chemweb/apache2/http-cchem/htdocs/username/index.html/public_html/
#12 (1) go-ahead with
/users/chemweb/apache2/http-cchem/htdocs/username/index.html/public_html/
[OK]
Line #6 above looks correct to me so I don't understand why mod_rewrite
tried the other possibilities.
I'm guessing all these problem have something to do with directory
protection but if this is true then I don't understand why URL #1
works.
Any ideas?
Cordially,
--
Jon Forrest
Unix Computing Support
College of Chemistry
173 Tan Hall
University of California Berkeley
Berkeley, CA
94720-1460
510-643-1032
jlforrest@berkeley.edu
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Very Puzzling Question About mod_rewrite
Posted by so...@apache.org.
On 11/1/07, Jon Forrest <jl...@berkeley.edu> wrote:
> (This is on Solaris 10-x86 with Apache 2.2.4)
> When I give the URL
> 1) http://www-demo.cchem.berkeley.edu/username/public_html
>
> everything works fine. However, for historical reasons,
> I can't require that people give the "/public_html" at
> the end of the URL. In other words, I want users to
> be able to enter
> 2) http://www-demo.cchem.berkeley.edu/username/
>
> to see the same results as produced by URL #1 .
> So, I decided to try mod_rewrite. I use the following
> in the proper VirtualHost section of my httpd.conf file:
>
> RewriteEngine on
> RewriteRule ^(.+)$ $1/public_html/ [L]
>
> This doesn't work. The client sees a "403 Forbidden" message.
> The apache log says:
> "Directory index forbidden by Options directive:
> /users/chemweb/apache2/http-cchem/htdocs/username/public_html/"
>
> I don't understand why I'm getting this message when
> URL #1 above works.
>
> The rewrite log shows the following (I added the #numbers):
>
> #1 (2) init rewrite engine with requested uri /username/
> #2 (3) applying pattern '^(.+)$' to uri '/username/'
> #3 (2) rewrite '/username/' -> '/username//public_html/'
> #4 (2) local path result: /username//public_html/
> #5 (2) prefixed with document_root to
> /users/chemweb/apache2/http-cchem/htdocs/username/public_html/
> #6 (1) go-ahead with
> /users/chemweb/apache2/http-cchem/htdocs/username/public_html/ [OK]
> #7 (2) init rewrite engine with requested uri /username/index.html
> #8 (3) applying pattern '^(.+)$' to uri '/username/index.html'
> #9 (2) rewrite '/username/index.html' -> '/username/index.html/public_html/'
> #10 (2) local path result: /username/index.html/public_html/
> #11 (2) prefixed with document_root to
> /users/chemweb/apache2/http-cchem/htdocs/username/index.html/public_html/
> #12 (1) go-ahead with
> /users/chemweb/apache2/http-cchem/htdocs/username/index.html/public_html/
> [OK]
>
> Line #6 above looks correct to me so I don't understand why mod_rewrite
> tried the other possibilities.
>
> I'm guessing all these problem have something to do with directory
> protection but if this is true then I don't understand why URL #1
> works.
>
> Any ideas?
>
> Cordially,
> Jon Forrest
Try some basic settings before mod_rewrite.
- DirectoryIndex sets the file that Apache will serve if a directory
is requested.
- UserDir is the name of the directory appended onto a user's home
directory if a ~user request is received.
UserDir public_html
DirectoryIndex index.html
http://www-demo.cchem.berkeley.edu/~username
will serve:
/home/username/public_html/index.html
If you do not want the tilde (~) in the URLs, use mod_rewrite to add it.
RewriteEngine On
RewriteRule ^/(.*)$ /~$1 [P]
If you want to continue with the ideas in the long thread, think about
why httpd is attempting to find username directories under
/users/chemweb/apache2/htdocs/cchem. Is that what you want?
solprovider
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Very Puzzling Question About mod_rewrite (**Solved**)
Posted by Jon Forrest <jl...@berkeley.edu>.
Krist van Besien wrote:
>
> However since it is /username/ that you need to replace with
> /username/public_html/ it shouldn't be that hard.
>
> RewriteRule ^`/(\w+)/(.+)$ /$1/public_html/$2 [L]
This was very close. With the expert help of a local Apache
guru, we came up with the following, which appears to work:
RewriteRule ^/(.+?)/(.*)$ /$1/public_html/$2 [L]
It's critical that the first part of the regular expression
use minimal matching.
Thanks for everyone's help.
Cordially,
--
Jon Forrest
Unix Computing Support
College of Chemistry
173 Tan Hall
University of California Berkeley
Berkeley, CA
94720-1460
510-643-1032
jlforrest@berkeley.edu
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Very Puzzling Question About mod_rewrite
Posted by Krist van Besien <kr...@gmail.com>.
On Nov 2, 2007 2:59 AM, Jon Forrest <jl...@berkeley.edu> wrote:
> Joshua Slive wrote:
> > On Nov 1, 2007 8:45 PM, Jon Forrest <jl...@berkeley.edu> wrote:
> >> Joshua Slive wrote:
> >>
>
> >> Thanks. After doing what you suggest I can see a directory
> >> listing of http://www-demo.cchem.berkeley.edu/username/ which
> >> shows the index.html file. However, if I click on index.html
> >> I get a "404 Not Found" error, and the error log says
> >>
> >> File does not exist:
> >> /users/chemweb/apache2/http-cchem/htdocs/username/index.html
> >
> > So, where is the file actually located?
>
> /users/chemweb/apache2/htdocs/cchem/username/public_html/index.html
>
> I was hoping to put "public_html" after "username" in every
> access. I think my rewrite rules need to be more complicated.
That will indeed be needed.
However since it is /username/ that you need to replace with
/username/public_html/ it shouldn't be that hard.
RewriteRule ^`/(\w+)/(.+)$ /$1/public_html/$2 [L]
This will only work however if your user name only contains normal
characters and no slashes, but I assumed that this was the case.
Krist
(Disclaimer: I didn't get around to actually testing the above)
--
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Very Puzzling Question About mod_rewrite
Posted by Jon Forrest <jl...@berkeley.edu>.
Joshua Slive wrote:
> On Nov 1, 2007 8:45 PM, Jon Forrest <jl...@berkeley.edu> wrote:
>> Joshua Slive wrote:
>>
>> Thanks. After doing what you suggest I can see a directory
>> listing of http://www-demo.cchem.berkeley.edu/username/ which
>> shows the index.html file. However, if I click on index.html
>> I get a "404 Not Found" error, and the error log says
>>
>> File does not exist:
>> /users/chemweb/apache2/http-cchem/htdocs/username/index.html
>
> So, where is the file actually located?
/users/chemweb/apache2/htdocs/cchem/username/public_html/index.html
I was hoping to put "public_html" after "username" in every
access. I think my rewrite rules need to be more complicated.
--
Jon Forrest
Unix Computing Support
College of Chemistry
173 Tan Hall
University of California Berkeley
Berkeley, CA
94720-1460
510-643-1032
jlforrest@berkeley.edu
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Very Puzzling Question About mod_rewrite
Posted by Joshua Slive <jo...@slive.ca>.
On Nov 1, 2007 8:45 PM, Jon Forrest <jl...@berkeley.edu> wrote:
> Joshua Slive wrote:
>
> > Likely because your Options directive is applied by-url rather than
> > by-directory.
> >
> > You need
> > <Directory /full/path/to/userdirectories/*/public_html>
> > Options +Indexes
> > </Dirctory>
> >
> > Or you need to find the Options directive that currently applies to
> > those directories and add Indexes.
>
> Thanks. After doing what you suggest I can see a directory
> listing of http://www-demo.cchem.berkeley.edu/username/ which
> shows the index.html file. However, if I click on index.html
> I get a "404 Not Found" error, and the error log says
>
> File does not exist:
> /users/chemweb/apache2/http-cchem/htdocs/username/index.html
So, where is the file actually located?
Joshua.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Very Puzzling Question About mod_rewrite
Posted by Jon Forrest <jl...@berkeley.edu>.
Joshua Slive wrote:
> Likely because your Options directive is applied by-url rather than
> by-directory.
>
> You need
> <Directory /full/path/to/userdirectories/*/public_html>
> Options +Indexes
> </Dirctory>
>
> Or you need to find the Options directive that currently applies to
> those directories and add Indexes.
Thanks. After doing what you suggest I can see a directory
listing of http://www-demo.cchem.berkeley.edu/username/ which
shows the index.html file. However, if I click on index.html
I get a "404 Not Found" error, and the error log says
File does not exist:
/users/chemweb/apache2/http-cchem/htdocs/username/index.html
The rewrite log says:
(2) init rewrite engine with requested uri /username/index.html
(3) applying pattern '^(.+)$' to uri '/username/index.html'
(2) rewrite '/username/index.html' -> '/username/index.html/public_html/'
(2) local path result: /username/index.html/public_html/
(2) prefixed with document_root to
/users/chemweb/apache2/http-cchem/htdocs/username/index.html/public_html/
I don't think the rewrite rule I'm using is correct.
Cordially,
--
Jon Forrest
Unix Computing Support
College of Chemistry
173 Tan Hall
University of California Berkeley
Berkeley, CA
94720-1460
510-643-1032
jlforrest@berkeley.edu
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org
Re: [users@httpd] Very Puzzling Question About mod_rewrite
Posted by Joshua Slive <jo...@slive.ca>.
On Nov 1, 2007 8:13 PM, Jon Forrest <jl...@berkeley.edu> wrote:
> (This is on Solaris 10-x86 with Apache 2.2.4)
>
> When I give the URL
>
> 1) http://www-demo.cchem.berkeley.edu/username/public_html
>
> everything works fine. However, for historical reasons,
> I can't require that people give the "/public_html" at
> the end of the URL. In other words, I want users to
> be able to enter
>
> 2) http://www-demo.cchem.berkeley.edu/username/
>
> to see the same results as produced by URL #1 .
> So, I decided to try mod_rewrite. I use the following
> in the proper VirtualHost section of my httpd.conf file:
>
> RewriteLogLevel 5
> RewriteLog "/users/chemweb/apache2/logs/rewrite.log"
> RewriteEngine on
> RewriteRule ^(.+)$ $1/public_html/ [L]
>
> This doesn't work. The client sees a "403 Forbidden" message.
> The apache log says:
>
> "Directory index forbidden by Options directive:
> /users/chemweb/apache2/http-cchem/htdocs/username/public_html/"
>
> I don't understand why I'm getting this message when
> URL #1 above works.
Likely because your Options directive is applied by-url rather than
by-directory.
You need
<Directory /full/path/to/userdirectories/*/public_html>
Options +Indexes
</Dirctory>
Or you need to find the Options directive that currently applies to
those directories and add Indexes.
Joshua.
---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
" from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org