You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Eric Covener <co...@gmail.com> on 2008/11/05 02:21:39 UTC

Re: [users@httpd] mod_rewrite rule

On Tue, Nov 4, 2008 at 4:16 PM, Seb <sp...@gmail.com> wrote:
> Hi,
>
> I'm having trouble specifying a seemingly very simple rewrite rule in
> .htaccess, where I simply want to redirect from say
> http://some.host.com/path to http://some.host.com/Path, and any
> subdirectories of course.  I thought this would do it:
>
> RewriteRule  ^path(.*)$  /Path$1  [last]
>
> but it doesn't.  Any help would be appreciated.


What does it do?  Can you enable the RewriteLog?  Do you have
RewriteEngine on? Are your htaccess files being read (AllowOverride
none)

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
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] Re: mod_rewrite rule

Posted by Eric Covener <co...@gmail.com>.
On Tue, Nov 4, 2008 at 8:59 PM, Seb <sp...@gmail.com> wrote:
> On Tue, 4 Nov 2008 20:49:39 -0500,
> "Eric Covener" <co...@gmail.com> wrote:
>
>> On Tue, Nov 4, 2008 at 8:35 PM, Seb <sp...@gmail.com> wrote:
>>> On Tue, 4 Nov 2008 20:21:39 -0500,
>>> "Eric Covener" <co...@gmail.com> wrote:
>>> and my user needs to have a directory Path/ have a lower case URI (as
>>> http://some.host.com/~user/path).  With the rule I tried:
>
>
>>> RewriteRule ^path(.*)$ Path$1 [last]
>
>>> I get:
>
>>> ---<---------------cut here---------------start-------------->--- Not
>>> Found The requested URL /home/user/WWW/Path was not found on this
>>> server.  ---<---------------cut
>>> here---------------end---------------->---
>
>>> which is closer.  WWW is the directory set as public via mod_userdir.
>
>> Closer to what?  What path do you want it to be rewritten to?
>
> Well, /home/user/WWW/Path is the right path in the local file system,
> but, as I said, I need it to go to http://some.host.com/~user/path.

Can you clarify what "go to" means? Do you want it to redirect?

> Why
> is the whole host URI that the rule actually matched not placed in the
> substitution?  It seems ridiculous to have to do that in the right hand
> side of the rule, when the left hand side obviously matched, so how does
> one write that right hand side?

The right hand side is a path in the filesystem, not a URL, in the
general case. A full URL if you're redirecting or proxying.


-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
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


[users@httpd] Re: mod_rewrite rule

Posted by Seb <sp...@gmail.com>.
On Tue, 4 Nov 2008 20:49:39 -0500,
"Eric Covener" <co...@gmail.com> wrote:

> On Tue, Nov 4, 2008 at 8:35 PM, Seb <sp...@gmail.com> wrote:
>> On Tue, 4 Nov 2008 20:21:39 -0500,
>> "Eric Covener" <co...@gmail.com> wrote:
>> and my user needs to have a directory Path/ have a lower case URI (as
>> http://some.host.com/~user/path).  With the rule I tried:


>> RewriteRule ^path(.*)$ Path$1 [last]

>> I get:

>> ---<---------------cut here---------------start-------------->--- Not
>> Found The requested URL /home/user/WWW/Path was not found on this
>> server.  ---<---------------cut
>> here---------------end---------------->---

>> which is closer.  WWW is the directory set as public via mod_userdir.

> Closer to what?  What path do you want it to be rewritten to?

Well, /home/user/WWW/Path is the right path in the local file system,
but, as I said, I need it to go to http://some.host.com/~user/path.  Why
is the whole host URI that the rule actually matched not placed in the
substitution?  It seems ridiculous to have to do that in the right hand
side of the rule, when the left hand side obviously matched, so how does
one write that right hand side?


-- 
Seb


---------------------------------------------------------------------
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] Re: mod_rewrite rule

Posted by Eric Covener <co...@gmail.com>.
On Tue, Nov 4, 2008 at 8:35 PM, Seb <sp...@gmail.com> wrote:
> On Tue, 4 Nov 2008 20:21:39 -0500,
> "Eric Covener" <co...@gmail.com> wrote:
> and my user needs to have a directory Path/ have a lower case URI (as
> http://some.host.com/~user/path).  With the rule I tried:


> RewriteRule ^path(.*)$ Path$1 [last]
>
> I get:
>
> ---<---------------cut here---------------start-------------->---
> Not Found
> The requested URL /home/user/WWW/Path was not found on this server.
> ---<---------------cut here---------------end---------------->---
>
> which is closer.  WWW is the directory set as public via mod_userdir.

Closer to what?  What path do you want it to be rewritten to?

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
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


[users@httpd] Re: mod_rewrite rule

Posted by Seb <sp...@gmail.com>.
On Tue, 4 Nov 2008 20:21:39 -0500,
"Eric Covener" <co...@gmail.com> wrote:

[...]

> What does it do?  Can you enable the RewriteLog?  Do you have
> RewriteEngine on? Are your htaccess files being read (AllowOverride
> none)

Yes, the .htaccess file at the top of the user public directory works
really well, and it only has 3 lines:

---<---------------cut here---------------start-------------->---
RewriteEngine on
RewriteRule	^weblog?(.*)$	/cgi-bin/pyblosxom.cgi$1   [L]
RewriteRule     ^gallery?(.*)$  /gallery2$1                [L]
---<---------------cut here---------------end---------------->---

and my user needs to have a directory Path/ have a lower case URI (as
http://some.host.com/~user/path).  With the rule I tried:

RewriteRule ^path(.*)$ /Path$1 [last]

I get:

---<---------------cut here---------------start-------------->---
Not Found
The requested URL /Path was not found on this server.
---<---------------cut here---------------end---------------->---

and if I try:

RewriteRule ^path(.*)$ Path$1 [last]

I get:

---<---------------cut here---------------start-------------->---
Not Found
The requested URL /home/user/WWW/Path was not found on this server.
---<---------------cut here---------------end---------------->---

which is closer.  WWW is the directory set as public via mod_userdir.


-- 
Seb


---------------------------------------------------------------------
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] mod_rewrite rule

Posted by André Warnier <aw...@ice-sa.com>.
Robert T Wyatt wrote:
> Yes, in a community with 70,000 users and millions of hits a day, the
> admins don't like every department to have access to httpd.conf.
> 
:-)
Ok, I can understand them.
Although one could wonder, then, why they allow .htaccess files anyway. 
  I believe said departments could cause a reasonable amount of trouble 
just there, no ?
A bit off-topic, I know, so let's leave it at that.
Sorry for butting in, I just wanted to know.


---------------------------------------------------------------------
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] mod_rewrite rule

Posted by Robert T Wyatt <ro...@gmail.com>.
Yes, in a community with 70,000 users and millions of hits a day, the
admins don't like every department to have access to httpd.conf.

Eric Covener wrote:
> On Wed, Nov 5, 2008 at 5:46 AM, André Warnier <aw...@ice-sa.com> wrote:
>> I mean, before Apache even gets to the .htaccess file, it has to find the
>> path to the directory wher the .htaccess file is.  And once it finds it, it
>> would have to re-interpret that same path and change it.
>> It does not seem to make a lot of sense..
>>
>> Now, if instead of being in the .htaccess file, it was in the httpd.conf,
>> then it would be another matter.
> 
> There are complications with using per-directory rewrite, but none of
> them are really insurmountable. Generally it's no problem to hop
> around the fileystem even when the rules are in .htaccess.
> 

---------------------------------------------------------------------
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] mod_rewrite rule

Posted by Eric Covener <co...@gmail.com>.
On Wed, Nov 5, 2008 at 5:46 AM, André Warnier <aw...@ice-sa.com> wrote:
> I mean, before Apache even gets to the .htaccess file, it has to find the
> path to the directory wher the .htaccess file is.  And once it finds it, it
> would have to re-interpret that same path and change it.
> It does not seem to make a lot of sense..
>
> Now, if instead of being in the .htaccess file, it was in the httpd.conf,
> then it would be another matter.

There are complications with using per-directory rewrite, but none of
them are really insurmountable. Generally it's no problem to hop
around the fileystem even when the rules are in .htaccess.

-- 
Eric Covener
covener@gmail.com

---------------------------------------------------------------------
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] mod_rewrite rule

Posted by Krist van Besien <kr...@gmail.com>.
On Wed, Nov 5, 2008 at 11:46 AM, André Warnier <aw...@ice-sa.com> wrote:

> On the other hand, in the Apache 2.2 mod_rewrite on-line help, there is this
> paragraph :
> RewriteRule  can be used in per-directory config files (.htaccess). In such
> a case, it will act locally, stripping the local directory prefix before
> processing, and applying rewrite rules only to the remainder. When
> processing is complete, the prefix is automatically added back to the path.
>
> Now, isn't the above (the original OP question) kind of a chicken-and-egg
> issue ?
>
> I mean, before Apache even gets to the .htaccess file, it has to find the
> path to the directory wher the .htaccess file is.  And once it finds it, it
> would have to re-interpret that same path and change it.
> It does not seem to make a lot of sense..

That's why after the substitution apache restarts an internal request.
That's also in the documentation...

Krist

-- 
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] mod_rewrite rule

Posted by André Warnier <aw...@ice-sa.com>.
Eric Covener wrote:
> On Tue, Nov 4, 2008 at 4:16 PM, Seb <sp...@gmail.com> wrote:
>> Hi,
>>
>> I'm having trouble specifying a seemingly very simple rewrite rule in
>> .htaccess, where I simply want to redirect from say
>> http://some.host.com/path to http://some.host.com/Path, and any
>> subdirectories of course.  I thought this would do it:
>>
>> RewriteRule  ^path(.*)$  /Path$1  [last]
>>
>> but it doesn't.  Any help would be appreciated.
> 
> 
> What does it do?  Can you enable the RewriteLog?  Do you have
> RewriteEngine on? Are your htaccess files being read (AllowOverride
> none)
> 
Hi.  Sorry to butt in with what may look at first unrelated to the 
problem at hand, but.

I regularly see on this list a bunch of questions related to 
RewriteRule's used in .htaccess files.

On the other hand, in the Apache 2.2 mod_rewrite on-line help, there is 
this paragraph :
RewriteRule  can be used in per-directory config files (.htaccess). In 
such a case, it will act locally, stripping the local directory prefix 
before processing, and applying rewrite rules only to the remainder. 
When processing is complete, the prefix is automatically added back to 
the path.

Now, isn't the above (the original OP question) kind of a 
chicken-and-egg issue ?

I mean, before Apache even gets to the .htaccess file, it has to find 
the path to the directory wher the .htaccess file is.  And once it finds 
it, it would have to re-interpret that same path and change it.
It does not seem to make a lot of sense..

Now, if instead of being in the .htaccess file, it was in the 
httpd.conf, then it would be another matter.

---------------------------------------------------------------------
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