HTML Logo by World Wide Web Consortium (www.w3.org). Click to learn more about our commitment to accessibility and standards.

Moving forward with Composr

ocPortal has been relaunched as Composr CMS, which is now in beta. ocPortal 9 will be superseded by Composr 10.

Head over to compo.sr for our new site, and to our migration roadmap. Existing ocPortal member accounts have been mirrored.


Another 301 redirect question

Login / Search

 [ Join | More ]
 Add topic 
Posted
Rating:
#77125 (In Topic #15876)
Avatar

Community saint

I am going to move some images from the galleries to a catalog. What I want to do is for every item in the gallery, just redirect them to the appropriate catalog category rather then the specific image.

In looking around for examples, it seems you need to always specify the specific old file to redirect. I am wondering if there is a way to use some kind of wildcard or something to redirect every old URL to this new catalog category.

The structure of the existing indexed URLs is:

Code

http://DOMAIN.com/galleries/misc/cartoons.htm?probe_type=image&probe_id=30

How do I designate that I want all those URLs with the various probe parameters?

Thanks for any help.

Bob

Back to the top
 
Posted
Rating:
#77129
Avatar

Community saint

Maybe this will push you in the right direction:

Code

RewriteRule ^(.*).htm?probe_type=image&probe_id=30$ /bla/bla/..../destination_page.htm  [NC,L,R=301]

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#77130
Avatar

Community saint

Hey temp-

The problem I have is that the probe_id parameter can be anything from 30 up to 47. Is there any way to designate that in a single line of code.

It also seems like I would want to include cartoons.htm, as that is the gallery that is being moved to the catalog. That way, even if the numbers were somehow used, they would not be a match because of the different gallery.

I just want to make sure that anything that includes /galleries/misc/cartoons.htm points to the new catalog.

Or am I way off base?

Thanks for your help.

Bob
Back to the top
 
Posted
Rating:
#77132
Avatar

Community saint

If you are narrowing it down to cartoons.htm, then there is probably no need to even try to restrict probe_id to 30-47. So this should do:

Code

RewriteRule ^(.*)/cartoons.htm?probe_type=image&probe_id=(.*)$ /bla/bla/..../destination_page.htm  [NC,L,R=301]
If it turns out that you still need the 30-47 restriction then try this:

Code

RewriteRule ^(.*)/cartoons.htm?probe_type=image&probe_id=(3[0-9]|4[0-7])$ /bla/bla/..../destination_page.htm  [NC,L,R=301]
As regex doesn't really know about numbers (it only knows characters/digits) then a range of 30-47 had to be described in two parts joined with an or directive as follows:

30-39 ← 3[0-9]
| ← or directive
40-47 ← 4[0-7]

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#77150
Avatar

Community saint

Thanks, yet again, temp-

I have not done this yet because my client and I are deciding on how we want the cartoons grouped and displayed, but I'll post back which form works to help others with the same question.

Thanks, again.

Bob


Back to the top
 
Posted
Rating:
#77154
Avatar

Community saint

temp-

I've tried both forms of the rewrite but neither seems to work. This is the code for both:

Code

# Move cartoons from galleries to catalogs
#RewriteRule ^(.*)/cartoons.htm?probe_type=image&probe_id=(.*)$ $1/catalogues/category/image-gallery/cartoons/world-war-ii-cartoons.htm  [NC,L,R=301]
RewriteRule ^(.*)/cartoons.htm?probe_type=image&probe_id=(3[0-9]|4[0-7])$ $1/catalogues/category/image-gallery/cartoons/world-war-ii-cartoons.htm  [NC,L,R=301]

I have cleared my browser cache.

They still end up at the old page. I haven't deleted the old gallery yet. That would not cause this not to work, would it?

Thanks for your help.

Bob


Last edit: by BobS
Back to the top
 
Posted
Rating:
#77158
Avatar

Community saint

Ok, did a bit of quick research and discovered that parameter matching has to be done in RewriteCond not RewriteRule. So in that case what you need is:

Code

RewriteCond %{QUERY_STRING} ^probe_type=image&probe_id=(3[0-9]|4[0-7])$
RewriteRule ^(.*)/cartoons.htm$ /catalogues/category/image-gallery/cartoons/world-war-ii-cartoons.htm [NC,L,R=301]
Some quick testing in Test your RewriteRules for Apache mod_rewrite and it seems to do the trick.

Note that I dropped the $1 variable from the $1/catalogues/… so that it goes to the correct page. With $1, it will go to:

Code

/galleries/misc/catalogues/category/image-gallery/cartoons/world-war-ii-cartoons.htm
and without it it goes to:

Code

/catalogues/category/image-gallery/cartoons/world-war-ii-cartoons.htm

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#77159
Avatar

Community saint

Thank you so much, temp.

I was wondering about including $1 but noticed that most other rules had it. Seems that would not have done the job anyway.

One question: what does the %{QUERY_STRING} represent in the condition?

Thanks again.

Bob
Back to the top
 
Posted
Rating:
#77175
Avatar

Community saint

BobS said

I was wondering about including $1 but noticed that most other rules had it.
That's because most rules can typically be written more efficiently to group similar URLs together. For example, lets say you have the following:

Code

http://bobspets.com/animals/cat/info.htm
http://bobspets.com/animals/dog/info.htm
. . .
http://bobspets.com/animals/hamster/info.htm
which you want redirected to

Code

http://bobspets.com/pets/cat/info.htm
http://bobspets.com/pets/dog/info.htm
. . .
http://bobspets.com/pets/hamster/info.htm
You could either do it the long way, redirecting every URL individually like so:

Code

RewriteRule ^animals/cat/info.htm$ pets/cat/info.htm
RewriteRule ^animals/dog/info.htm$ pets/dog/info.htm
. . .
RewriteRule ^animals/hamster/info.htm$ pets/hamster/info.htm
which can get very long if you have dozens of pets, or you can look for a common pattern to simplify it.

The source URL structure is consistent, and the target URL structure is consistent, with the only variable being pet type. This means we can reduce it down to a single rule:

Code

RewriteRule ^animals/(.*)/info.htm$ pets/$1/info.htm
Which is achieved by collecting the variable part of the source URL (.*) into the $1 variable which can then be used in the target URL.

Most redirects typically only need one variable which $1 is why so common. If you see $2, $3 … $9 in the second (target) part of the rewrite rule, it just means that there is a corresponding 2nd, 3rd etc. set of brackets in the first (source) part.

BobS said

One question: what does the %{QUERY_STRING} represent in the condition?
%{QUERY_STRING} = URL parameters, i.e. everything after the "?".

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#77176
Avatar

Community saint

Thanks, for the explanation, temp. That all makes sense now.

You must have been responsible for training at some point in your career because you certainly seem to know how to explain stuff to those less knowledgeable.

Thanks again for your help.

Bob
Back to the top
 
Posted
Rating:
#77181
Avatar

Community saint

BobS said

You must have been responsible for training at some point in your career because you certainly seem to know how to explain stuff to those less knowledgeable.
Only for most of my working life  ;) .

Most of the software I designed and developed, and content, was specifically for training or educational purposes.

Do you have a Samsung Galaxy S / Galaxy S II ? If so, why not check out my ScreenFree FM Radio .
Back to the top
 
Posted
Rating:
#77182
Avatar

Community saint

Well, it's our good fortune to have you here - you are certainly an asset to these forums.

Bob
Back to the top
 
Posted
Rating:
#77185
Avatar

Community saint

:thumbs:

Take my advice. I'm not using it!

View my working ocPortal site (version 9.x.x) at Anglo-Indian Portal
Back to the top
 
1 guests and 0 members have just viewed this: None
Control functions:

Quick reply   Contract

Your name:
Your message: