Forum Moderators: phranque

Message Too Old, No Replies

Variable redirect?

         

medwebguy

5:24 am on Jan 30, 2009 (gmt 0)

10+ Year Member



Yet another newbie hoping for some help after spending some hours reading...

I'm using a Redirect rule to simplify the URLs for a number of standard images, such as:

Redirect permanent /img/2195/100/a.html /image?id=2195&size=100

But I've had to issue a separate statement for every image. I'm wondering if it is possible to make a general rule such as:

Redirect permanent /img/fubar/100/a.html /image?id=fubar&size=100

where 'fubar' is a variable so I can pass any image number to the single line.

I believe this can be done with Rewrite, but my host does not appear to allow Rewrite to be used.

Thanks to anyone who can point me towards a solution. I'm sure this must have been answered a dozen times or more, but if so, I haven't been able to find it.

Mike

jdMorgan

4:29 pm on Jan 30, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Three problems:

First, if you really want a redirect, you'll need to use RedirectMatch, which accepts a regular-expressions pattern as part of the URL-path on the left, and allows you to back-reference all or parts of the requested URL which match that pattern, for use in the substitution URL on the right.

Second, the Redirect directive requires a canonical URL to be specified on the right side; Your directive shows only a URL-path. In other words, it must read "http://example.com/image?id=fubar&size=100 ".

Lastly, realize that the effect of a redirect is to tell the client that the URL has changed, and that the new URL should be used to access the content. So, you are telling the search engines that you want to use "example.com/image?id=2195&size=100" as the URL, and that is what will show up in search results.

As a result, I strongly believe that what you want to do here is to internally rewrite client requests for the URL "http://example.com/img/2195/100/a.html" to the internal filepath "/image?id=2195&size=100" without exposing this action to the HTTP clients (browsers & robots). To do this, you need to use mod_rewrite, and specify the internal rewrite syntax rather than the external redirect syntax.

This is a simple "static URL to dynamic filepath" rewrite, a subject well-covered in our forum and in our forum library. Also, links to some very useful resources are provided in our forum Charter (see links at top of this page).

Jim

medwebguy

10:16 pm on Jan 30, 2009 (gmt 0)

10+ Year Member



Thanks, Jim. I appreciate the suggestions. I will do as you suggest and look for more information in your forum library.

Mike

medwebguy

4:32 am on Jan 31, 2009 (gmt 0)

10+ Year Member



Hey! I figured it out! I'm re-writing URLs like a champ!

Thanks again for your help. Armed with your tips, a more careful search resulted in some tutorials that really explained it all for me.

Mike

jdMorgan

2:48 pm on Jan 31, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it figured out!

Jim