Forum Moderators: phranque

Message Too Old, No Replies

"?" becomes "%3F" in RedirectMatch :-(

         

Claes100

1:07 pm on Nov 21, 2007 (gmt 0)

10+ Year Member



Hi all,
can someone please help an apache beginner with the following:

I have an existing ASP site running on apache. For a couple of reasons I want to redirect all attempts reaching documents in a doc directory to a single .asp page. That works fine today using RedirectMatch

BUT, when I try to add a request parameter using "?" after the file name, it converts to the url encoded "%3F" and the .asp file is not found.
How can I preserve the question mark (?) in my RedirectMatch?

RedirectMatch ^\/dir1\/(docdir\/.*)$1 http://example.se/check.asp?doc=$1

(ends up as http://example.se/check.asp%3Fdoc=docdir/mydoc.pdf)

Many thanks!

/Claes

[edited by: jdMorgan at 11:27 pm (utc) on Nov. 22, 2007]
[edit reason] examplified [/edit]

jdMorgan

3:16 pm on Nov 21, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I suggest using mod_rewrite instead of mod_alias, and adding the [NE] flag (NoEscape) to the rule.

Jim

Claes100

2:07 pm on Nov 22, 2007 (gmt 0)

10+ Year Member



Thanks Jim,
my web host says they support mod_rewrite so I tried the following lines in my .htaccess file in the root:

RewriteEngine on
RewriteBase /pros/full
RewriteRule ^(/se/documents/.*)$ checkDocPermission.asp?doc=$1 [NE]

But when I click the document link
http://www.example.se/pros/full/se/documents/assignment.doc
I am NOT redirected to checkDocPermission.asp.

Have I missed something essential...?

Thanks!
/Claes

[edited by: jdMorgan at 11:27 pm (utc) on Nov. 22, 2007]
[edit reason] examplified [/edit]

jdMorgan

2:17 pm on Nov 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't address the RewriteBase directive without knowing where your .htaccess file is located in your directory structure or the details of how your server directory structure is set up, but at least the following corrections are needed:

RewriteRule ^(se/documents/.*)$ http://www.example.com/checkDocPermission.asp?doc=$1 [R=301,NE,L]

Review the RewriteBase documentation to be sure you need to use it and are using it correctly.

It's usually better to start with "RewriteBase /" and then if you get an error, adjust it as needed based on your server error log information. Note that paths seen by RewriteRule in .htaccess do not include the leading slash, and that RewriteBase should include a trailing slash.

Jim

Claes100

3:00 pm on Nov 22, 2007 (gmt 0)

10+ Year Member



Hi again Jim,
thanks a lot for your help, it's now working exactly the way I want!

:-))

Claes