LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 10-31-2011, 11:51 AM   #1
milkon1
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Rep: Reputation: Disabled
Smile Url rewrite capitalization


URL Rewrite

hi there i have the below code

when a lower case url is passed in it fails because linux is case sensitive

i need this rewrite to point to /open311/%1/services/$1.xml

however if the jurisdiction_is passed is lowercase i need it converted to redirect to
the same only with the first letter capitalised

eg if jurisdiction_id=presales must convert to Presales

any help would be great

thanks

#GET Service Definition
RewriteCond %{QUERY_STRING} ^&?jurisdiction_id=([^&]+)$
RewriteRule ^/open311/services/(.*)\.xml /open311/%1/services/$1.xml? [NC][L]
RewriteRule ^/open311/services/(.*)\.xml /open311/default/services/$1.xml? [NC][L]
 
Old 10-31-2011, 11:52 AM   #2
milkon1
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
i know its to do with converting this to first letter capital and rest lower but dont know how

([^&]+)$
 
Old 10-31-2011, 01:41 PM   #3
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Use toupper internal rewrite map.

Here is an example. Let us assume you want to capitalize the first letter of the jurisdiction_id query string parameter:
Code:
RewriteMap toupper int:toupper
RewriteCond %{QUERY_STRING} ^&*jurisdiction_id=([^&])([^&]*)
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%1}%2/services/$1.xml [NC,L]
However, that will only work if jurisdiction_id is the only parameter. Let's fix that by matching both cases (at the beginning, and at elsewhere, in the query string):
Code:
RewriteMap toupper int:toupper
RewriteCond %{QUERY_STRING} ^jurisdiction_id=([^&])([^&]*) [OR]
RewriteCond %{QUERY_STRING} &jurisdiction_id=([^&])([^&]*)
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%1}%2/services/$1.xml [NC,L]
The above converts the initial letter to uppercase, but retains the rest of the value as-is. If you want to canonicalize the jurisdiction_id , then lowercase the rest of it:
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING} ^jurisdiction_id=([^&])([^&]*) [OR]
RewriteCond %{QUERY_STRING} &jurisdiction_id=([^&])([^&]*)
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%1}${tolower:%2}/services/$1.xml [NC,L]
If you also want to make sure the final XML file name is in lower case, use
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING} ^jurisdiction_id=([^&])([^&]*) [OR]
RewriteCond %{QUERY_STRING} &jurisdiction_id=([^&])([^&]*)
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%1}${tolower:%2}/services/${tolower:$1}.xml [NC,L]
When you have one query parameter, you usually end up having another, at least occasionally. It is therefore a good idea to retain the rest of the query parameters, too. If the target is a script, it can then utilize the parameters; otherwise the query parameters are ignored. In any case, they do no harm, and the extra processing time taken should be truly neglible.
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING}     ^()&*jurisdiction_id=([^&])([^&]*)(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^&*(.+)&+jurisdiction_id=([^&])([^&]*)(.*)$
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%2}${tolower:%3}/services/${tolower:$1}.xml?%1%4 [NC,L]
Note that since either condition may match, we use an empty pair of parentheses in the first one, so that both conditions have (logically) the same referable parts.

The above removes the jurisdiction_id from the query string. If you wish to retain it also, in its original form, use
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING}     ^()&*jurisdiction_id=([^&])([^&]*)(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^&*(.+)&+jurisdiction_id=([^&])([^&]*)(.*)$
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%2}${tolower:%3}/services/${tolower:$1}.xml?jurisdiction_id=%2%3&%1%4 [NC,L]
or, to retain it in canonicalized form:
Code:
RewriteMap toupper int:toupper
RewriteMap tolower int:tolower
RewriteCond %{QUERY_STRING}     ^()&*jurisdiction_id=([^&])([^&]*)(.*)$ [OR]
RewriteCond %{QUERY_STRING} ^&*(.+)&+jurisdiction_id=([^&])([^&]*)(.*)$
RewriteRule ^/+open311/+services/+(.+)\.xml$ /open311/${toupper:%2}${tolower:%3}/services/${tolower:$1}.xml?jurisdiction_id=${toupper:%2}${tolower:%3}&%1%4 [NC,L]
I hope you find the step-wise development of the solution informative,

Last edited by Nominal Animal; 10-31-2011 at 01:43 PM.
 
Old 11-01-2011, 11:13 AM   #4
milkon1
LQ Newbie
 
Registered: Oct 2011
Posts: 3

Original Poster
Rep: Reputation: Disabled
Smile

thanks for the help

solved the issue without any doubt
 
Old 11-06-2011, 11:38 AM   #5
cheesus
Member
 
Registered: Jan 2005
Location: Munich, Germany
Distribution: SuSE
Posts: 186

Rep: Reputation: 25
then please click "mark solved" and "helpful Yes".
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
rewrite rule for url change ravibhure Linux - Server 2 01-21-2010 09:12 PM
URL rewrite rule not working... vikram_cvk Linux - Software 1 12-03-2008 02:14 AM
URL rewrite help needed rino.caldelli Linux - Server 4 09-28-2007 04:19 PM
Mod REWRITE url rewriting gabsik Linux - Networking 1 09-29-2006 05:24 AM
apache url rewrite gallew Linux - Server 0 08-25-2006 03:54 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:00 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration