views:

175

answers:

3

I had an issue playing with Gallery when I changed a setting. However, I noticed there is a pattern to the error:

The URLs look as such:
main.php/d/number/name.jpg

"number" is dynamic (ie "9496-2")
"name" is dynamic (ie "all+clad+7pc+b")

Everything else is static.

Unfortunately, when I made the setting change, the "number" portion then changed from "9496-2" to "9495-2".

How can I subtract the value "1" from variable "number"?

Thanks in advanced!

Jeff

A: 

This should do it.

RewriteEngine On
RewriteBase /
RewriteRule ^photos/ebay/main.php/d/([0-9]*)6-([0-9]*)/(.*).jpg /photos/ebay/main.php/d/$1\5-$2/$3.jpg [QSA,L]

I know you said you already got it but here is a solution without an additional script. (And I actually tested this one to ensure that \5 works).

Sionide21
Thanks for the quick response. "9496-2" is dynamic too. I'm thinking I need to split that number at the dash, and subtract one from the first part?
Jefe
Ok, this should do that. The ($1) may not work as I have never tried that before but that shoudl be a simple google.
Sionide21
Using "($1)" actually adds in the ( ) on either side of the variable.
Jefe
Ok, this one finally works :)
Sionide21
A: 

You didn't say which part of your URLs are fixed an which parts vary, so I'm just going to guess:

RewriteEngine on
RewriteBase /
RewriteRule ^/photos/ebay/main.php/d/9496-2/(.*)$ /photos/ebay/main.php/d/9495-2/$1 [QSA,L]

You may also want to add R=301 to the flags if you'd like to send a redirect back to clients. (as-is, this should just do an "internal redirect")

Laurence Gonsalves
I was able to get this to work for one case, with a little modification:RewriteRule ^main.php/d/9496-2/(.*)$ /photos/ebay/main.php/d/9495-2/$1 [QSA,L]
Jefe
A: 

Here is the solution that worked. It involved using a .htaccess file and a PHP script.

.htaccess file:
Create the ".htaccess" file with the below content:

RewriteEngine On
RewriteBase /

# Redirect to PHP Script
RewriteRule ^main.php/d/([0-9]*)-([0-9])/(.*)$ scriptName.php?v1=$1&v2=$2&v3=$3 [R=301,QSA,L]

PHP Script:
Create the "scriptName.php", then add in your logic. In my case, I needed to subtract "1" from v1.

NOTE: make sure the .htaccess and PHP script are in the same path.

Jefe