Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-03-25
3
Medium Priority
?
200 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

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…
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, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses
Course of the Month11 days, 3 hours left to enroll

618 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