?
Solved

help with Apache Mod_Rewrite rule

Posted on 2010-01-12
4
Medium Priority
?
382 Views
Last Modified: 2012-05-08
Hello All,

I'm trying to rewrite a URL to make it more SEO friendly. I have tried many different rewrite rules but can't seem to get it working properly.

Here is what I'm trying to do. I would like to rewrite a URL like this:

http://photo.mysite.com/photos/_firstname_lastname_city_state_usernum_123.456.789C.jpg

The values of firstname, lastname, city, state, usernum amd photo number up until the C.jpg will be variable.

Here is another example:

http://photo.mysite.com/photos/_joe_smith_losangeles_ca_2345_123.456.789C.jpg

I would like to use Apache rewrite to strip out everything between /photos/ and 123.456.789C.jpg and replace the dots (periods) between 123,456 and 789 with / .

So I want the rewrite to look like this:

http://photo.mysite.com/photos/123/456/789C.jpg

Additional info: the last 9 digits before the "C.jpg" will always be 9 digits (ie. 123.456.789)

Any help will be greatly appreciated!!
0
Comment
Question by:chris0011
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 26

Expert Comment

by:arober11
ID: 26301670
Hi

If you have access to the httpd.conf, stick something along the following lines in your VirtualHost definition, end check the mod_rewrite is loaded:

RewriteEngine On
RewriteRule /photos/_[a-zA-Z]*_[a-zA-Z]*_[a-zA-Z]*_[a-zA-Z][a-zA-Z]_[a-zA-Z0-9]*_([0-9]*).([0-9]*).([0-9]*C.jpg)   /photos/$1/$2/$3 [L]

Else you will need to loose the leading '/' and add the rules to a .htaccess file, e.g. for a .htaccess in your Document root:

RewriteEngine On
RewriteBase /
RewriteRule photos/_[a-zA-Z]*_[a-zA-Z]*_[a-zA-Z]*_[a-zA-Z][a-zA-Z]_[a-zA-Z0-9]*_([0-9]*).([0-9]*).([0-9]*C.jpg)   /photos/$1/$2/$3 [L]
0
 

Author Comment

by:chris0011
ID: 26307998
Hi Arober11,

Thanks for your help.

Unfortunately, the rewrite rule still isn't catching the URL.

When I go to -- http://10.10.1.42/photos/_keta_pat_ahemedabad_india_2345_000.001.994C.jpg I get this error in the apache error log:

[Wed Jan 13 12:20:26 2010] [error] [client 192.168.0.78] File does not exist: /mysite_photos_final/_keta_pat_ahemedabad_india_2345_000.001.994C.jpg

Not sure what I'm missing here.

thanks again,

-A
0
 
LVL 26

Accepted Solution

by:
arober11 earned 2000 total points
ID: 26310040
Hi

That URL has a "country name" rather than two character "state code" in it, this should support both formats:

RewriteEngine On
RewriteRule /photos/_[a-zA-Z]*_[a-zA-Z]*_[a-zA-Z]*_[a-zA-Z]*_[a-zA-Z0-9]*_([0-9]*).([0-9]*).([0-9]*C.jpg)   /photos/$1/$2/$3 [L]
0
 

Author Comment

by:chris0011
ID: 26355522
Thanks Arober11,

This worked:

RewriteRule /photos/[a-zA-Z0-9+-,'.)(]*_[a-zA-Z0-9+-,')(]*_[a-zA-Z0-9+-,')(]*_[a-zA-Z0-9+-,')(]*_[a-zA-Z0-9+-,']*_[a-zA-Z0-9+-,']*_[a-zA-Z0-9+-,']*_[a-zA-Z0-9]*_([0-9]*)\.([0-9]*)\.([0-9]*C\.jpg)   /photos/$1/$2/$3 [PT,L]

thanks a lot for your help.

-A
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

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

If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses
Course of the Month9 days, 15 hours left to enroll

762 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