Hello ,
I am trying a redirection scenario for which I need your guidance.
**Original URLs**
- https
://www.example.com/books -- single URI
- https
://www.example.com/books/author -- Double URI
- https
://www.example.com/cd/rock/west - Triple URI
**Redirected URLs:**
- https
://www.example.net/newbooks -- single URI
- https
://www.example.net/newbooks/newauthor -- Double URI
- https
://www.example.net/newcd/newrock/newwest - Triple URI
For the above given URLs, redirection must be applied using rewrite Map.
Current key value pair are in keys.txt file like this.
----------
- **books** https
://www.example.net/newbooks
- **books/author** https
://www.example.net/newbooks/newauthor
- **cd/jazz/western** https
://www.example.net/newcd/newrock/newwest
----------
**Current Solution only handles single URI pattern, handles any case in the URI **
- RewriteMap lowercase int:tolower
- RewriteMap mymap txt:/folderstructure/keys.txt
- RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9]+)/?$ [NC]
- RewriteRule ^/(.*) ${mymap:${lowercase:%1}} [L,R=301]
**Question :** How to extract multiple URI values between "/" (forward slashes in the REQUEST_URI) values and contact into a single key to be supplied as argement to ${mymap:${lowercase:?}}. It is must to call the tolower function, for the reason that URI in the original URL may come in mixedcase.
**For example :**
If the incoming URL is https
://www.example.com/BooKS/AuThOr (mixedcase)
the URI value (BooKS/AuThOr) must be converted to lowercase and the final key for look must be "books/author" in the rewrite rule.
**The below piece of code is not robust, but it solved the problem temporarily **
keys.txt
----------
- books https
://www.example.net/newbooks
- author https
://www.example.net/newbooks/newauthor
- western https
://www.example.net/newcd/newrock/newwest
----------
- RewriteCond %{REQUEST_URI} ^/books/([A-Za-z0-9]+)/?$ [NC]
- RewriteRule ^/(.*) ${mymap:${lowercase:%1}} [L,R=301]
----------
- RewriteCond %{REQUEST_URI} ^/cd/rock/([A-Za-z0-9]+)/?$ [NC]
- RewriteRule ^/(.*) ${mymap:${lowercase:%1}} [L,R=301]
Thanks.
[edited by: phranque at 1:45 am (utc) on Apr 15, 2015]
[edit reason] Please Use example.com [webmasterworld.com] [/edit]