?
Solved

mod_rewrite - how to create a rule based on first letter of a directory?

Posted on 2004-03-25
3
Medium Priority
?
199 Views
Last Modified: 2010-03-04
Hello,

I am a mod_rewrite newbie.  Can someone help me create a rule, perhaps using a map, to change urls based upon the first letter of the first directory after the server root?

For example,
http://www.server.com/apple/index.html gets mapped to /contenta/apple/index.html
and
http://www.server.com/apple/slice/index.php is mapped to /contenta/apple/slice/index.php

similarly,
http://www.server.com/bananna/slice/peel/index.php maps to /contentb/bananna/slice/peel/index.php
and
http://www.server.com/bananna/index.php  to /contentb/bananna/index.php

I hope that is clear ... files off the root such as http://www.site.com/index.html would also get their own mapping to /content_index or something like that.

Thank you for the help!
0
Comment
Question by:Beans0063
[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
3 Comments
 
LVL 27

Accepted Solution

by:
BigRat earned 1000 total points
ID: 10686086
Try :-

RewriteRule ^/(.)(.+)$     /content$1/$2   [L]

This maps everything to /contentx/..... Could you explain your second requirement a little more exactly? Do you mean that "plain" URLs like /file.html should be mapped into "content_file.html"?

In which case we'd need something like :-


RewriteRule  ^/([^/]+)$   /content_$1   [L]

as the FIRST rule in the rule list.

HTH
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 11785104
No comment has been added to this question in more than 21 days, so it is now classified as abandoned..
I will leave the following recommendation for this question in the Cleanup topic area:

    ACCEPT: BigRat

Any objections should be posted here in the next 4 days. After that time, the question will be closed.

Periwinkle
EE Cleanup Volunteer
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…
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 …
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…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses
Course of the Month8 days, 2 hours left to enroll

765 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