Solved

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

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

In my time as an SEO for the last 2 years and in the questions I have assisted with on here I have always seen the need to redirect from non-www urls to their www versions. For instance redirecting http://domain.com (http://domain.com) to http…
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 seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

746 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

11 Experts available now in Live!

Get 1:1 Help Now