Solved

mod url rewrite cannot decode + sign

Posted on 2009-06-29
9
1,395 Views
Last Modified: 2012-06-27
I have used htaccess to di my redirecting of pages but i am unable to pass a parameter with '+' sign in it

i have tried
RewriteRule ^articles/(.+)/([0-9]+)/$ category.php?category_name=$1&pageNo=$2 [NE]

this is what i typed in my url -> http://www.mywebsite.com/articles/Food+Drink/1/
i did an echo on the parameter category_name on the redirected page and it reflects Food Drink, the + sign is missing

please kindly assist me on this
0
Comment
Question by:ginola29
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 8

Expert Comment

by:lharrispv
ID: 24740223
This is not exactly what you are asking but you might be able to gleam some info from it anyway.

http://www.experts-exchange.com/Software/Server_Software/Web_Servers/Apache/Q_23647266.html
0
 
LVL 8

Expert Comment

by:lharrispv
ID: 24740235
Here is another one for you.  It comes from:http://www.webmasterworld.com/apache/3890963.htm

Neither problem can be fixed simply by modifying the regex.
in the first case, the code is specifically "skipping" the rewrite if a period or slash is found in the requested (pretty) url and no colon precedes those characters (whether immediately-preceding or not). The intent is apparently to avoid rewriting urls that have filetypes appended, such as "robots.txt" or "index.php" itself.

in the second case, it is likely the script itself changing plus signs to spaces, as this is a common thing, for example among most search engines.

So the first question to ask is, "Can you do without periods and plus signs in titles?" Noting that these are titles --such as used in newspapers-- periods are never used, and I doubt that plus signs are ever used, either.

If the answer is "No," then you'll probably have to go with a rewriting solution that is a lot less efficient. And by that I mean "very inefficient" and may not be suitable for a high-traffic site. You will also have to modify the Wiki script to fix the plus sign problem, as that can't be fixed in mod_rewrite.

Modification for "period" problem:

# Rewrite url-path requests with no periods or slashes (unless preceded by a colon) to script
RewriteRule ^([^./]+¦[^:]*:[^./]*[./].*)$ /index.php?title=$1 [QSA,L]
#
# Else rewrite only if requested url-path does not end with any of the listed
# filetypes and does not resolve to a physically-existing directory or file
RewriteCond $1 !\.(gif¦jpe?g¦png¦php[345]?¦s?html?¦xml¦js¦css¦txt¦rdf¦pdf¦flv¦swf¦wmv¦mpe?g[234]?¦avi¦mp3)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?title=$1 [QSA,L]

It is the additional second rule and how it works that is inefficient: Any requested url-path with a period or slash which is not preceded by a colon and that does not end with the specifically-listed filetypes will result in two calls to the operating system's file manager --and possibly in two disk reads-- to go see if the requested url-path resolves to an actually-existing physical file or directory. These extra disk functions may slow the site perceptibly if you get a *lot* of traffic, meaning hundreds of thousands of hits per day. You can reduce the number of checking operations by specifically excluding certain filetypes from being checked as shown, but note that any "filetype" that you exclude here cannot be used at the end of a 'title' in your Wiki. The list shown here is meant to be illustrative, rather than comprehensive: add or remove filetypes to suit your site's needs. Filetypes appearing in the list cannot appear at the end of Wiki titles, but won't result in a disk check. You must decide where to strike the 'balance' based on what is important to you.

Also, order the filetype-exclusion list based on your 'hit-count' stats, with the most frequently-requested filetypes at the beginning of the list.

Again it's a balance between executing more mod_rewrite code, titling freedom, and disk-check time.

Important: Replace the broken pipe "¦" characters with solid pipes before use; Posting on this forum modifies the pipe characters, and the code won't work if the broken pipes are not corrected.

And again, the problem with plus signs is not resolvable by mod_rewrite -- I'd suggest you either avoid the use of that character, or use preg_replace in a "patch" in the script to substitute either a different character or the word "plus" for all occurrences of that character in your title links (look for the "link printing" or "get title from database" directives, and add the preg_replace in or near those lines).

I should also say that I don't know why the original code looked for colons -- It may have something to do with the urls produced by the Wiki script; Perhaps you can include periods and slashes in Wiki titles if you precede them with a colon (check the documentation, as you may not even need to modify this code). But I attempted to copy that functional behaviour into the new code above, and will leave that issue for you to investigate.

0
 
LVL 4

Expert Comment

by:TurboBorland
ID: 24740248
Because it's considered an illegal character as it is used for things outside of just the symbol.  Did you try to convert the + sign to %2B and trying that out?
0
 

Author Comment

by:ginola29
ID: 24740259
i've tried using php's rawurlencode and converted it to %2B, but it still doesn't work
0
VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

 
LVL 17

Expert Comment

by:jasonsbytes
ID: 24740560
You really should avoid using + sign in URL's.  There is much documentation about this being a bad idea.

Can you use a different character?
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 24741041
Using the B flag should fix your issue. The B flag will work from version 2.2.12 (not released yet). There's a bug in versions below 2.2.12. Therefore you'll have to recompile mod_rewrite with the latest http://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x/modules/mappers/mod_rewrite.c
0
 

Author Comment

by:ginola29
ID: 24742651
hi caterham, i do not have access to my web server, is there any other solutions?
0
 
LVL 27

Expert Comment

by:caterham_www
ID: 24743597
You could convert a space into a + in php, e.g. with ereg_replace or preg_replace.
$result = preg_replace('/ /', '+', $input);

Open in new window

0
 

Accepted Solution

by:
ginola29 earned 0 total points
ID: 24748936
thanks guys for you assistance, but i think i found my solution to my question

this article solved my problem
http://www.mediawiki.org/wiki/Manual:Short_URL/Allowing_for_escaped_characters_in_URI
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jQuery detect if it is a mobile device 3 90
Append letter to end of string 4 36
How to use md5 hashing 3 25
WordPress syntax 2 23
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

939 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

5 Experts available now in Live!

Get 1:1 Help Now