Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

mod url rewrite cannot decode + sign

Posted on 2009-06-29
9
Medium Priority
?
1,484 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
[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
  • 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
Building an interactive eFuture classroom

Watch and learn how ATEN provided a total control system solution including seamless switching matrix switch, HDBaseT extenders, PDU, lighting control to build an interactive eFuture classroom.

 

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
 
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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
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 count occurrences of each item in an array.

688 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