mod_rewrite in user directory

mod_rewrite in user directory

am 06.10.2007 22:47:47 von teel

Hi there!
I'm having problems setting up a mod_rewrite on Apache 2.2.3. I have
an address like this: http://127.0.0.1/~tomek/somesite/register.php
and it works ok. I've got a /home/tomek/public_html/somesite/.htaccess
file which contains:
RewriteEngine On
RewriteRule ^(.+)\.html$ $1.php [L]
The rule in this special example is simple (my target one is much more
complicated but that's not the problem): it should substiture html
with php and that's all. But when requesting this uri:
http://127.0.0.1/~tomek/somesite/register.html (HTML instead of PHP) I
get this 404 error: "The requested URL /home/tomek/public_html/
somesite/register.php was not found on this server."
So mod_rewrite successfully replaced html with php but Apache
converted this uri to the filesystem path, don't know why. By the way
the file do exists on the filesystem.

I've been searching a lot and one of the tips may be this from
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html:
"Home directory expansion
When the substitution string begins with a string resembling "/
~user" (via explicit text or backreferences), mod_rewrite performs
home directory expansion independent of the presence or configuration
of mod_userdir.
This expansion does not occur when the PT flag is used on the
RewriteRule directive."

Unfortunately it does not work, but maybe it's not what my problem is.
Mine substitution string does not contain ~user, it actually is
"register.html".

Does anybody has any idea how to solve this problem? I have to be able
to use mod_rewrite with url containing ~user. What is this filesystem
conversion from?

Best regards,
teel

Re: mod_rewrite in user directory

am 06.10.2007 23:08:17 von teel

And this is what RewriteLog says, it looks good:

teel127.0.0.1 - - [06/Oct/2007:23:05:43 +0200] [127.0.0.1/sid#819e6a8]
[rid#839b8c8/initial] (3) [perdir /home/tomek/public_html/somesite/]
strip per-dir prefix: /home/tomek/public_html/somesite/register.html -
> rejestracja.html
127.0.0.1 - - [06/Oct/2007:23:05:43 +0200] [127.0.0.1/sid#819e6a8]
[rid#839b8c8/initial] (3) [perdir /home/tomek/public_html/somesite/]
applying pattern '(.+)\.html$' to uri 'register.html'
127.0.0.1 - - [06/Oct/2007:23:05:43 +0200] [127.0.0.1/sid#819e6a8]
[rid#839b8c8/initial] (2) [perdir /home/tomek/public_html/somesite/]
rewrite 'register.html' -> 'register.php'
127.0.0.1 - - [06/Oct/2007:23:05:43 +0200] [127.0.0.1/sid#819e6a8]
[rid#839b8c8/initial] (3) [perdir /home/tomek/public_html/somesite/]
add per-dir prefix: register.php -> /home/tomek/public_html/somesite/
register.php
127.0.0.1 - - [06/Oct/2007:23:05:43 +0200] [127.0.0.1/sid#819e6a8]
[rid#839b8c8/initial] (1) [perdir /home/tomek/public_html/somesite/]
internal redirect with /home/tomek/public_html/somesite/register.php
[INTERNAL REDIRECT]

Best regards,
teel

Re: mod_rewrite in user directory

am 07.10.2007 17:22:17 von Kees Nuyt

On Sat, 06 Oct 2007 13:47:47 -0700, teel
wrote:

>Hi there!
>I'm having problems setting up a mod_rewrite on Apache 2.2.3. I have
>an address like this: http://127.0.0.1/~tomek/somesite/register.php
>and it works ok. I've got a /home/tomek/public_html/somesite/.htaccess
>file which contains:
>RewriteEngine On
>RewriteRule ^(.+)\.html$ $1.php [L]
>The rule in this special example is simple (my target one is much more
>complicated but that's not the problem): it should substiture html
>with php and that's all. But when requesting this uri:
>http://127.0.0.1/~tomek/somesite/register.html (HTML instead of PHP) I
>get this 404 error: "The requested URL /home/tomek/public_html/
>somesite/register.php was not found on this server."
>So mod_rewrite successfully replaced html with php but Apache
>converted this uri to the filesystem path, don't know why. By the way
>the file do exists on the filesystem.
>
>I've been searching a lot and one of the tips may be this from
>http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html:
>"Home directory expansion
>When the substitution string begins with a string resembling "/
>~user" (via explicit text or backreferences), mod_rewrite performs
>home directory expansion independent of the presence or configuration
>of mod_userdir.
>
>This expansion does not occur when the PT flag is used on the
>RewriteRule directive."

Thank you for doing so much research by yourself!

>Unfortunately it does not work, but maybe it's not what my problem is.
>Mine substitution string does not contain ~user, it actually is
>"register.html".

Your substitution string doesn't contain it explicitly, but the
_backreference_ $1 does begin with /~tomek/, so this rule
actually applies.
Try [LPT] or something like that. Perhaps [L,PT], I'm no very
familiar with rewrites.

>Does anybody has any idea how to solve this problem? I have to be able
>to use mod_rewrite with url containing ~user. What is this filesystem
>conversion from?
>
>Best regards,
>teel

Good luck!
--
( Kees
)
c[_] Clairvoyants meeting canceled due to unforeseen events. (#449)

Re: mod_rewrite in user directory

am 07.10.2007 17:27:22 von teel

On 7 Pa , 17:22, Kees Nuyt wrote:
> Your substitution string doesn't contain it explicitly, but the
> _backreference_ $1 does begin with /~tomek/, so this rule
> actually applies.
> Try [LPT] or something like that. Perhaps [L,PT], I'm no very
> familiar with rewrites.

And this part does not work unfortunately. Neither [L] nor [L,PT], nor
[PT] ([LPT] causes a 500 error).

Thanks anyway!

Best regards,
teel

Re: mod_rewrite in user directory

am 08.10.2007 21:56:18 von teel

Ok, I've got the final solution! :) It is the RewriteBase, not the PT
flag.

RewriteEngine On
RewriteBase /~username/somesite/
RewriteRule .....

Best regards,
teel