Multiple Subfolders - Different Result

Oh, the strange things mod_rewrite does!

Multiple Subfolders - Different Result

Postby sharingsunshine » Fri Dec 19, 2008 7:45 am

I have a site that I have upgraded to a new picture gallery. Within the gallery there are 3 subfolders. Within each subfolder are folders related to that topic.

I am using a redirect match right now. This works but it is getting very cumbersome because there are upwards of 30 different album names that correspond to 1 of the 3 subfolder names.

For example, I have 3 main folders named family, pets and travel. Within each folder there are many subfolders. Currently I have them listed in an either/or fashion. Like this, (folder1|folder2|folder3).

My question with over a 100 subfolders (between the 3 main folders) is there an easier way to accomplish this? By the way, the many subfolders follow no pattern to separate them through pattern matching.

Here is an example:

Code: Select all
#####Checking For Travel Albums and Redirecting

RedirectMatch 301 /picalbum/?(albums)?/(hainesville2008|/CR2008|costa+rica/fincalunanueva|flaselva|huntsvillescarecrow|huntsvillegardens|CRchildrenmuseum|seaportvillage|monticellonaturalization|ivycreek|uvahomes|morven|SantaAnaCA|santarosa|oldtowntemecula|anzaborrego|balboapark|capistrano|ENC-CA)/?((([aA-zZ_]+[0-9]+)|P(A|B)?([0-9]*)|IMG_([0-9]*)(.*)|([0-9_]+)([aA-zZ_]+)|([aA-zZ_0-9]+))?\.?(highlight.)?(jpg)?)?$ http://www.anydomain.com/picalbum/travel/$1/$2


This works fine until someone just wants /gallery/crla/

In other words, don't want to look at a specific image but instead want to look at the overall page for the album.

So, I have 2 questions:
1. Is there an easier way than listing all the subfolders individually for each main folder?
2. How can I get it to work for just a request like /picalbum/crla/ ?

Thanks,

Randal
sharingsunshine
 
Posts: 55
Joined: Tue Dec 19, 2006 5:32 am

Postby richardk » Sat Dec 20, 2008 10:52 am

1. Is there an easier way than listing all the subfolders individually for each main folder?

You could use
Code: Select all
[^/]+

to match any sub directory.

2. How can I get it to work for just a request like /picalbum/crla/ ?

Where should it redirect to? I would add another RedirectMatch as your current rule is already quite complicated.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sharingsunshine » Sat Dec 20, 2008 1:55 pm

Thanks for getting back to me. I have been trying to break down the redirect match, by taking out portions of it, but I still get a url with a ? at the end.

I am getting a url that is like this:
http://www.anydomain.com/picalbum/relva/IMG_2501?full=1

Code: Select all
RedirectMatch 301 /picalbum/?(albums)?/(relva|barbershop)/IMG_([0-9]+)(.*)$ /p23_album/v/travel_7/$2/IMG_$3.jpg.html?


The url comes out with a ? at the end causing to to be a 404.

Please tell me how to get rid of the ?. If I remove the ? at the end of the new url I get the full query string.

You answered this statement:
1. Is there an easier way than listing all the subfolders individually for each main folder?

You could use
Code:
[^/]+

This won't work because the subfolders can go to 1 of 3 main folders. That is why I was asking is there a way to do that more efficiently. Sorry I didn't make that clear.

Thanks,

Randal
sharingsunshine
 
Posts: 55
Joined: Tue Dec 19, 2006 5:32 am

Postby richardk » Sun Dec 21, 2008 9:59 am

A few examples would help me understand what you want.

I have been trying to break down the redirect match, by taking out portions of it, but I still get a url with a ? at the end.

...

Please tell me how to get rid of the ?. If I remove the ? at the end of the new url I get the full query string.

If you do it with mod_rewrite any empty query string (just a ?) should be removed. Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^picalbum(?:/albums)?/(relva|barbershop)/IMG_([0-9]+)(.*)$ /p23_album/v/travel_7/$2/IMG_$3.jpg.html? [R=301,L]


The url comes out with a ? at the end causing to to be a 404.

Does that happen for all files or just those files?

This won't work because the subfolders can go to 1 of 3 main folders. That is why I was asking is there a way to do that more efficiently. Sorry I didn't make that clear.

Now i understand. Then no there is not.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sharingsunshine » Mon Dec 22, 2008 11:47 am

I tried the rewrite rule you gave me but I still get the ?full=1 at the end of the url.

Here is what I have:
Code: Select all
RewriteRule ^gallery(?:/albums)?/(laselva2008|zooave|flowerscritters|sanjose|crla|CRhomestay2008|fincalunanueva|CRchildrenmuseum)/IMG_([0-9]+)(.*)$ /gallery2.3/v/travel_7/costarica/$2/IMG_$3.jpg.html? [R=301,L]


The url in question is coming in as

http://www.anydomain.com/gallery/laselv ... 529?full=1

I want to change it to:
http://www.anydomain.com/gallery2.3/v/t ... 9.jpg.html?

It is changing it to:
http://www.anydomain.com/gallery2.3/v/t ... tml?full=1

Please help me to get rid of the query. Thanks,

Randal
sharingsunshine
 
Posts: 55
Joined: Tue Dec 19, 2006 5:32 am

Postby richardk » Mon Dec 22, 2008 4:17 pm

Did you clear your browser's cache? That rule should not do that.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sharingsunshine » Mon Dec 22, 2008 5:55 pm

I cleared the cache and I also tried it on a browser that hadn't been used or opened until I tested it. Each time it still comes back with the query ?full=0 attached to the end of the url.

Is there anything else I can try?

Thanks,

Randal
sharingsunshine
 
Posts: 55
Joined: Tue Dec 19, 2006 5:32 am

Postby richardk » Tue Dec 23, 2008 8:52 am

Try redirecting a much simpler URL that has a query string.

Are there any other rules, Redirects or RedirectMatches that could be causing the redirect?
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby sharingsunshine » Tue Dec 23, 2008 3:40 pm

I have looked to see if there are any conflicts and I can't seem to find any.

This is the easy query I tried:
http://www.anydomaincom/gallery/richmond2008?full=1

I put this query together:
### Simple Query Test ###########
RewriteRule ^gallery/richmond2008(.*)$ /gallery2.3/v/travel_7/richmond2008?
[R=301,L]

I even tried this one:
### Simple Query Test ###########
RewriteRule ^gallery/richmond2008$ /gallery2.3/v/travel_7/richmond2008? [R=301,L]

They both give http://www.anydomaincom/gallery2.3/v/tr ... 008?full=1

Can you suggest what I should look for that would cause the conflict? Or, would turning on the rewrite log help out in any way?

Thanks,

Randal
sharingsunshine
 
Posts: 55
Joined: Tue Dec 19, 2006 5:32 am

Postby richardk » Wed Dec 24, 2008 8:48 am

Try (first with absolutely nothing else in your .htaccess file and then with your other rules and redirects)
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^something_completely$ /defferent? [R,L]

then going to /something_completely?un=related.

Or, would turning on the rewrite log help out in any way?

Maybe, it can't hurt.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Next

Return to Idiosyncrasies

Who is online

Users browsing this forum: No registered users and 18 guests

cron