You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Johnny Edge <je...@visafirst.com> on 2009/03/18 21:05:08 UTC

[users@httpd] mod rewrite issue

 
Hello,
 
I have a Virtual host that utilizes mod rewrite in the following manner
 
 
<VirtualHost 192.168.0.127:80>

...
 
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /notfound.php?%{QUERY_STRING}

 
i.e. missing documents are passed to notfound.php
 
I also have a directory inside the VH which I want to pass such requests to a different script
 
 
<Directory "/var/www/html/info/admin/">

 AuthName "Restricted"
  NTLMAuth on
  NTLMAuthHelper "/usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp"
  NTLMBasicAuthoritative on
  AuthType NTLM
  require valid-user

RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^admin/(.*) /admin/index.php?%{QUERY_STRING} [L]
 
</Directory>

 
Still, http://info/admin/nonexistent will call notfound.php and not admin/index.php
 
 
Can you suggest a resolution to this?
 
Thanks,
 
J.
 
 
 
 
 

Re: [users@httpd] mod rewrite issue

Posted by Brian Mearns <me...@gmail.com>.
On Thu, Mar 19, 2009 at 9:51 AM, Johnny Edge <je...@visafirst.com> wrote:
>
> Custom 404 page breaks php SESSION vars (only GET/POST/REQUEST are available), or so the development department claims.

Hmm, that doesn't seem write, but I can't say for sure. I don't see
any reason cookies wouldn't be available...can only once confirm this
either way?

-Brian

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://pgp.mit.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] mod rewrite issue

Posted by Brian Mearns <me...@gmail.com>.
> On Wed, Mar 18, 2009 at 9:05 PM, Johnny Edge <je...@visafirst.com> wrote:
>>
>> Hello,
>>
>> I have a Virtual host that utilizes mod rewrite in the following manner
>>
>>
>> <VirtualHost 192.168.0.127:80>
>> ...
>>
>> RewriteEngine On
>> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
>> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
>> RewriteRule ^(.*) /notfound.php?%{QUERY_STRING}
>>
>> i.e. missing documents are passed to notfound.php
>>
>> I also have a directory inside the VH which I want to pass such requests to
>> a different script
>>
>>
>> <Directory "/var/www/html/info/admin/">
>>  AuthName "Restricted"
>>   NTLMAuth on
>>   NTLMAuthHelper "/usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp"
>>   NTLMBasicAuthoritative on
>>   AuthType NTLM
>>   require valid-user
>>
>> RewriteEngine On
>> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
>> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
>> RewriteRule ^admin/(.*) /admin/index.php?%{QUERY_STRING} [L]
>>
>> </Directory>
>>
>> Still, http://info/admin/nonexistent will call notfound.php and not
>> admin/index.php


Out of curiosity, why not use a custom 404 page?

-- 
Feel free to contact me using PGP Encryption:
Key Id: 0x3AA70848
Available from: http://pgp.mit.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] mod rewrite issue

Posted by Johnny Edge <je...@visafirst.com>.
Thanks Krist, moving out the rewrite statements from <Directory> and before other rewrites solved the problem.

J. 

-----Original Message-----
From: Krist van Besien [mailto:krist.vanbesien@gmail.com] 
Sent: 19 March 2009 13:07
To: users@httpd.apache.org
Subject: Re: [users@httpd] mod rewrite issue

On Wed, Mar 18, 2009 at 9:05 PM, Johnny Edge <je...@visafirst.com> wrote:
>
> Hello,
>
> I have a Virtual host that utilizes mod rewrite in the following 
> manner
>
>
> <VirtualHost 192.168.0.127:80>
> ...
>
> RewriteEngine On
> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond 
> %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteRule ^(.*) 
> /notfound.php?%{QUERY_STRING}
>
> i.e. missing documents are passed to notfound.php
>
> I also have a directory inside the VH which I want to pass such 
> requests to a different script
>
>
> <Directory "/var/www/html/info/admin/">
>  AuthName "Restricted"
>   NTLMAuth on
>   NTLMAuthHelper "/usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp"
>   NTLMBasicAuthoritative on
>   AuthType NTLM
>   require valid-user
>
> RewriteEngine On
> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond 
> %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteRule ^admin/(.*) 
> /admin/index.php?%{QUERY_STRING} [L]
>
> </Directory>
>
> Still, http://info/admin/nonexistent will call notfound.php and not 
> admin/index.php

Use:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d RewriteRule ^/info/admin/(.*) /admin/index.php?%{QUERY_STRING} [L]

And make sure that this is put _before_ the other RewriteRules, as it needs to match first. It is not necessary to put this in a <Directory> block.
(RewriteRule processing takes place before the URL -> Filename translation, so directives in <Directory> blocks are probably even ignored here)

Also, as you are not doing any query string mangling you can write your RewriteRule as:
RewriteRule ^/info/admin/(.*) /admin/index.php [QSA,L]

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


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

Posted by Krist van Besien <kr...@gmail.com>.
On Wed, Mar 18, 2009 at 9:05 PM, Johnny Edge <je...@visafirst.com> wrote:
>
> Hello,
>
> I have a Virtual host that utilizes mod rewrite in the following manner
>
>
> <VirtualHost 192.168.0.127:80>
> ...
>
> RewriteEngine On
> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
> RewriteRule ^(.*) /notfound.php?%{QUERY_STRING}
>
> i.e. missing documents are passed to notfound.php
>
> I also have a directory inside the VH which I want to pass such requests to
> a different script
>
>
> <Directory "/var/www/html/info/admin/">
>  AuthName "Restricted"
>   NTLMAuth on
>   NTLMAuthHelper "/usr/bin/ntlm_auth --helper-protocol=squid-2.5-ntlmssp"
>   NTLMBasicAuthoritative on
>   AuthType NTLM
>   require valid-user
>
> RewriteEngine On
> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
> RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
> RewriteRule ^admin/(.*) /admin/index.php?%{QUERY_STRING} [L]
>
> </Directory>
>
> Still, http://info/admin/nonexistent will call notfound.php and not
> admin/index.php

Use:

RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule ^/info/admin/(.*) /admin/index.php?%{QUERY_STRING} [L]

And make sure that this is put _before_ the other RewriteRules, as it
needs to match first. It is not necessary to put this in a <Directory>
block.
(RewriteRule processing takes place before the URL -> Filename
translation, so directives in <Directory> blocks are probably even
ignored here)

Also, as you are not doing any query string mangling you can write
your RewriteRule as:
RewriteRule ^/info/admin/(.*) /admin/index.php [QSA,L]

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 issue

Posted by Eric Covener <co...@gmail.com>.
On Wed, Mar 18, 2009 at 4:05 PM, Johnny Edge <je...@visafirst.com> wrote:

>
> <Directory "/var/www/html/info/admin/">
> RewriteRule ^admin/(.*) /admin/index.php?%{QUERY_STRING} [L]

The "admin" part of the URL is already stripped away for you,
including it in your pattern is making this fail to match.  Assuming
you don't have a .../admin/admin/.

RewriteLog would help.


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