Solved

need help with rewritting rules

Posted on 2011-09-21
3
256 Views
Last Modified: 2012-05-12
hello i have a question about rewriting rule
i have 4  thumbnails galery  that onmouseover display data and picture with ajax it's  associated with limits: 5 thumbnails are displayed starting display from limits given trough url, and an arrow able the visitor to see five more.

what i would like is to have a link to each thumb going to the same page than the script info display but displaying picture and infos through a google/ and robots friendly environnment that means no ajax but i would display the  <img src="myimage.jpg"> with myimage.jpg coming fom the location url




currenly i use the following rewriting rule:

RewriteRule ^print/([a-z]{2})/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/?$ /print.php?lang=$1&limite1=$2&limite2=$3&limite3=$4&limite4=$5
RewriteRule ^print/([^/]*) /print.php?lang=$1&limite1=0&limite2=0&limite3=0&limite4=0
but limits works only for one section  (board) at the moment

so i think it will evolve to something longer

and would give a location something like http://localhost/print/en/1/0/0/0/0/myimage.jpg

what do u thing?
would my rewriting rule  be like  this?

RewriteRule ^print/([a-z]{2})/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([a-z])/?$ /print.php?lang=$1&limite1=$2&limite2=$3&limite3=$4&limite4=$5&limite5=$6&image=$7

RewriteRule ^print/([^/]*) /print.php?lang=$1&limite1=0&limite2=0&limite3=0&limite4=0

thanks for your precious help



Sans-titre-1.jpg
0
Comment
Question by:jerrrrry
  • 2
3 Comments
 
LVL 35

Expert Comment

by:Terry Woods
ID: 36584795
Each number after a $ in the replacement refers back to a capturing group in the pattern ie it's a backreference. You can't have more backreferences than you have capturing groups.

Your rule:
RewriteRule ^print/([a-z]{2})/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([a-z])/?$ /print.php?lang=$1&limite1=$2&limite2=$3&limite3=$4&limite4=$5&limite5=$6&image=$7
has 6 capturing groups, but has a backreference to $7 so I believe it would fail with an error.

Could you please give some clarity as to which source URLs you want redirected to which target URLs. eg

"I want to redirect:
print/fr/
to
print.php?lang=fr&limite1=0&limite2=0&limite3=0&limite4=0

and
print/fr/5/
to
print.php?lang=fr&limite1=5&limite2=0&limite3=0&limite4=0
"
0
 

Author Comment

by:jerrrrry
ID: 36589487
i would like
to redirect

print/fr/1/0/0/0/0/folder/image.jpg

to print.php?lang=fr&galerie=1&limite1=0&limite2=0&limite3=0&limite4=0&show=folder/image.jpg


would it be wise?
maybe i don't need to use a folder/ and use directly the image but in a first time i would like to know how you can use it and redirect it

i would like to display the image using $show,
thanks
0
 
LVL 35

Accepted Solution

by:
Terry Woods earned 500 total points
ID: 36596220
For that example, I believe the rule should look like this:

RewriteRule ^print/([a-z]{2})/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ /print.php?lang=$1&galerie=$2&limite1=$3&limite2=$4&limite3=$5&limite4=$5&limite5=$6&show=$7

I changed the capturing group ([a-z]) to (.*) as previously it was looking for a single lowercase letter between two / characters, whereas actually you want it to be the folder and image name.

As for whether it's wise or not, you're probably best to ask that as a separate question and get some other expert's opinions. My specialty is the regular expressions side of things.
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now