You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by "Campbell, Lance" <la...@illinois.edu> on 2009/08/10 17:51:29 UTC

[users@httpd] Redirection problem with dynamic url parameters

I need to redirect:

https://illinois.edu/blog/view?blogId=291

To 

http://illinois.edu/db/view/291

The key is that 291 may be any number in both the from and to URLs.

Can someone point me in the proper direction on how to redirect these
types of URLs?

Thanks,

Lance Campbell
Project Manager/Software Architect/DBA
Web Services at Public Affairs
217-333-0382


Re: [users@httpd] Redirection problem with dynamic url parameters

Posted by Krist van Besien <kr...@gmail.com>.
On Mon, Aug 10, 2009 at 8:38 PM, Eric Covener<co...@gmail.com> wrote:
>> RewriteRule ^blog/view\?blogId=(\d+) http://illinois.edu/db/view/$1 [R=301]
>
> You can't match a query string like that. You have to use a RewriteCond.



Like this:

RewriteCond %{QUERY_STRING}  blogid=(\d+)
RewriteRule   /blog/view        /db/view/%1

Since you're staying on the same server you don't really need proxy or
redirect, unless you really want to change the URL as it appears in
the browser. In this case you'd use:

RewriteCond %{QUERY_STRING}  blogid=(\d+)
RewriteRule   /blog/view       http://illinois.edu/db/view/%1 [R,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] Redirection problem with dynamic url parameters

Posted by Eric Covener <co...@gmail.com>.
> RewriteRule ^blog/view\?blogId=(\d+) http://illinois.edu/db/view/$1 [R=301]

You can't match a query string like that. You have to use a RewriteCond.

-- 
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] Redirection problem with dynamic url parameters

Posted by Bob Ionescu <bo...@googlemail.com>.
2009/8/10 Jonathan Zuckerman <j....@gmail.com>:
> Ah dammit, obvious mistake, this is better:
> RewriteRule ^blog/view\?blogId=(\d+) http://illinois.edu/db/view/$1 [R=301]

But it won't work, because the query string is not part of the string
which is tested in your rule-pattern. As the docs states, you'll need
a RewriteCond to check the query string.

Bob

---------------------------------------------------------------------
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] Redirection problem with dynamic url parameters

Posted by Jonathan Zuckerman <j....@gmail.com>.
On Mon, Aug 10, 2009 at 11:02 AM, Jonathan
Zuckerman<j....@gmail.com> wrote:
> On Mon, Aug 10, 2009 at 8:51 AM, Campbell, Lance<la...@illinois.edu> wrote:
>> https://illinois.edu/blog/view?blogId=291
>>
>> To
>>
>> http://illinois.edu/db/view/291
>
> I think you want something like this:
>
> RewriteRule ^blog/view\?blogId=(\d)+ http://illinois.edu/db/view/$1 [R=301]
>
> Totally untested, it's been awhile but I think the + quantifier means
> "one or more of the preceeding"
>

Ah dammit, obvious mistake, this is better:
RewriteRule ^blog/view\?blogId=(\d+) http://illinois.edu/db/view/$1 [R=301]

---------------------------------------------------------------------
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] Redirection problem with dynamic url parameters

Posted by Jonathan Zuckerman <j....@gmail.com>.
On Mon, Aug 10, 2009 at 8:51 AM, Campbell, Lance<la...@illinois.edu> wrote:
> https://illinois.edu/blog/view?blogId=291
>
> To
>
> http://illinois.edu/db/view/291

I think you want something like this:

RewriteRule ^blog/view\?blogId=(\d)+ http://illinois.edu/db/view/$1 [R=301]

Totally untested, it's been awhile but I think the + quantifier means
"one or more of the preceeding"

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