Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1510
  • Last Modified:

mod url rewrite cannot decode + sign

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
ginola29
Asked:
ginola29
  • 3
  • 2
  • 2
  • +2
1 Solution
 
lharrispvCommented:
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
 
lharrispvCommented:
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
 
TurboBorlandCommented:
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
ginola29Author Commented:
i've tried using php's rawurlencode and converted it to %2B, but it still doesn't work
0
 
jasonsbytesCommented:
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
 
caterham_wwwCommented:
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
 
ginola29Author Commented:
hi caterham, i do not have access to my web server, is there any other solutions?
0
 
caterham_wwwCommented:
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
 
ginola29Author Commented:
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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now