You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by ap...@neondawn.net on 2008/11/04 02:39:22 UTC
[users@httpd] rewrite help
I am trying to get a redirect to work so that I can get friendl URLs for
my website. I am using mod_perl and have written a little handler as a
controler to handle all requests.
What I currently have that works as follows.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^wc/(.*) /wc\?uni=$1 [L]
The user types in: http://example.com/wc/docName
and apache rewrites: http://example.com/wc?arg=docName
Where /wc is my perl handler, as such:
PerlModule Examplepackage::WC
<Location /wc>
SetHandler perl-script
PerlResponseHandler Examplepackage::WC
</Location>
This works and it's great, but I want to work just a little different.
I want the user to type in: http://example.com/docName
and apache rewrite: http://example.com/wc?arg=docName
I have tried a few different RewriteRule types and either they 404 or
it exceedes 10 internal redirects (internal server error).
I have tried:
RewriteRule ^/(.*) /wc\?uni=$1 [L]
RewriteRule ^(.*) /wc\?uni=$1 [L]
RewriteRule /(.*) /wc\?uni=$1 [L]
RewriteRule . /wc\?uni=$1 [L]
RewriteRule /(.*)$ /wc\?uni=$1 [L]
and other such permutations.
What am I doing wrong?
---------------------------------------------------------------------
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] rewrite help
Posted by ap...@neondawn.net.
I have figured out the problem. Once apache tested the request URI it
tested it a second time as an internal redirect and would fail, or get
in a loop. So I just had to tell it not to check for /wc , which wasn't
excluded by the !-f and !-d because it doesn't exist on the filesystem
because it is a perl handler.
my config that works:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/wc
RewriteRule ^(.*)$ /wc?uni=$1 [L]
Thanks solprovider and André for your help.
Ukiah
On Tue, Nov 04, 2008 at 08:53:00AM +0100, André Warnier wrote:
> Also, maybe be aware that (.*) will match anything, even the empty
> string, so you may end up with "/wc?uni=" (unless as solprovider
> indicates, you have a different rule for "/").
> It may be better to use "^/(.+)$", which will only match if there is
> actually something after the /.
>
> solprovider@apache.org wrote:
> >Do not escape the question mark.
> >
> >RewriteRule ^/(.*) /wc?uni=$1 [L]
> >- the first character must be a slash and is not included in the $1
> >variable.
> >- Add "/wc?uni=" before the rest of the URL on the same server.
> >- Discard any querystring from the visitor. (No QSA flag.)
> >- [L] = stop processing RewriteRules.
> >
> >You may want another RewriteRule for /,
> >
> >HTH,
> >solprovider
> >
> >On 11/3/08, apache@neondawn.net <ap...@neondawn.net> wrote:
> >>I am trying to get a redirect to work so that I can get friendl URLs for
> >> my website. I am using mod_perl and have written a little handler as a
> >> controler to handle all requests.
> >>
> >> What I currently have that works as follows.
> >>
> >> RewriteEngine On
> >> RewriteBase /
> >> RewriteCond %{REQUEST_FILENAME} !-f [OR]
> >> RewriteCond %{REQUEST_FILENAME} !-d
> >> RewriteRule ^wc/(.*) /wc\?uni=$1 [L]
> >>
> >> The user types in: http://example.com/wc/docName
> >> and apache rewrites: http://example.com/wc?arg=docName
> >>
> >> Where /wc is my perl handler, as such:
> >>
> >> PerlModule Examplepackage::WC
> >> <Location /wc>
> >> SetHandler perl-script
> >> PerlResponseHandler Examplepackage::WC
> >> </Location>
> >>
> >> This works and it's great, but I want to work just a little different.
> >>
> >> I want the user to type in: http://example.com/docName
> >> and apache rewrite: http://example.com/wc?arg=docName
> >>
> >> I have tried a few different RewriteRule types and either they 404 or
> >> it exceedes 10 internal redirects (internal server error).
> >>
> >> I have tried:
> >> RewriteRule ^/(.*) /wc\?uni=$1 [L]
> >> RewriteRule ^(.*) /wc\?uni=$1 [L]
> >> RewriteRule /(.*) /wc\?uni=$1 [L]
> >> RewriteRule . /wc\?uni=$1 [L]
> >> RewriteRule /(.*)$ /wc\?uni=$1 [L]
> >> and other such permutations.
> >>
> >> What am I doing wrong?
> >
> >---------------------------------------------------------------------
> >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
---------------------------------------------------------------------
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] rewrite help
Posted by André Warnier <aw...@ice-sa.com>.
Also, maybe be aware that (.*) will match anything, even the empty
string, so you may end up with "/wc?uni=" (unless as solprovider
indicates, you have a different rule for "/").
It may be better to use "^/(.+)$", which will only match if there is
actually something after the /.
solprovider@apache.org wrote:
> Do not escape the question mark.
>
> RewriteRule ^/(.*) /wc?uni=$1 [L]
> - the first character must be a slash and is not included in the $1 variable.
> - Add "/wc?uni=" before the rest of the URL on the same server.
> - Discard any querystring from the visitor. (No QSA flag.)
> - [L] = stop processing RewriteRules.
>
> You may want another RewriteRule for /,
>
> HTH,
> solprovider
>
> On 11/3/08, apache@neondawn.net <ap...@neondawn.net> wrote:
>> I am trying to get a redirect to work so that I can get friendl URLs for
>> my website. I am using mod_perl and have written a little handler as a
>> controler to handle all requests.
>>
>> What I currently have that works as follows.
>>
>> RewriteEngine On
>> RewriteBase /
>> RewriteCond %{REQUEST_FILENAME} !-f [OR]
>> RewriteCond %{REQUEST_FILENAME} !-d
>> RewriteRule ^wc/(.*) /wc\?uni=$1 [L]
>>
>> The user types in: http://example.com/wc/docName
>> and apache rewrites: http://example.com/wc?arg=docName
>>
>> Where /wc is my perl handler, as such:
>>
>> PerlModule Examplepackage::WC
>> <Location /wc>
>> SetHandler perl-script
>> PerlResponseHandler Examplepackage::WC
>> </Location>
>>
>> This works and it's great, but I want to work just a little different.
>>
>> I want the user to type in: http://example.com/docName
>> and apache rewrite: http://example.com/wc?arg=docName
>>
>> I have tried a few different RewriteRule types and either they 404 or
>> it exceedes 10 internal redirects (internal server error).
>>
>> I have tried:
>> RewriteRule ^/(.*) /wc\?uni=$1 [L]
>> RewriteRule ^(.*) /wc\?uni=$1 [L]
>> RewriteRule /(.*) /wc\?uni=$1 [L]
>> RewriteRule . /wc\?uni=$1 [L]
>> RewriteRule /(.*)$ /wc\?uni=$1 [L]
>> and other such permutations.
>>
>> What am I doing wrong?
>
> ---------------------------------------------------------------------
> 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] rewrite help
Posted by so...@apache.org.
Do not escape the question mark.
RewriteRule ^/(.*) /wc?uni=$1 [L]
- the first character must be a slash and is not included in the $1 variable.
- Add "/wc?uni=" before the rest of the URL on the same server.
- Discard any querystring from the visitor. (No QSA flag.)
- [L] = stop processing RewriteRules.
You may want another RewriteRule for /,
HTH,
solprovider
On 11/3/08, apache@neondawn.net <ap...@neondawn.net> wrote:
> I am trying to get a redirect to work so that I can get friendl URLs for
> my website. I am using mod_perl and have written a little handler as a
> controler to handle all requests.
>
> What I currently have that works as follows.
>
> RewriteEngine On
> RewriteBase /
> RewriteCond %{REQUEST_FILENAME} !-f [OR]
> RewriteCond %{REQUEST_FILENAME} !-d
> RewriteRule ^wc/(.*) /wc\?uni=$1 [L]
>
> The user types in: http://example.com/wc/docName
> and apache rewrites: http://example.com/wc?arg=docName
>
> Where /wc is my perl handler, as such:
>
> PerlModule Examplepackage::WC
> <Location /wc>
> SetHandler perl-script
> PerlResponseHandler Examplepackage::WC
> </Location>
>
> This works and it's great, but I want to work just a little different.
>
> I want the user to type in: http://example.com/docName
> and apache rewrite: http://example.com/wc?arg=docName
>
> I have tried a few different RewriteRule types and either they 404 or
> it exceedes 10 internal redirects (internal server error).
>
> I have tried:
> RewriteRule ^/(.*) /wc\?uni=$1 [L]
> RewriteRule ^(.*) /wc\?uni=$1 [L]
> RewriteRule /(.*) /wc\?uni=$1 [L]
> RewriteRule . /wc\?uni=$1 [L]
> RewriteRule /(.*)$ /wc\?uni=$1 [L]
> and other such permutations.
>
> What am I doing wrong?
---------------------------------------------------------------------
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