Solved

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

Posted on 2004-03-25
3
193 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 250 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

Manage your data center from practically anywhere

The KN8164V features HD resolution of 1920 x 1200, FIPS 140-2 with level 1 security standards and virtual media transmissions at twice the speed. Built for reliability, the KN series provides local console and remote over IP access, ensuring 24/7 availability to all servers.

Question has a verified solution.

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

Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

732 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