3

On this page there are many abbreviation / acronym entries: http://abbreviations.wordcrow.com/acronyms/D/

They are generated in PHP:

<a href="/define/<?php echo rawurlencode($abbreviation['title'])?>/">
    <strong><?php echo $abbreviation['title']?></strong>
</a>

I used rawurlencode because many acronyms contain bizarre characters such as #, & and even /.

And the URL requests such as:

http://abbreviations.wordcrow.com/define/DA%26E/

Would first be fed to rawurldecode():

$acronym = rawurldecode('DA%26E'); // $acronym would be 'DA&E'.

And then used in database queries.

While DA&E is all right, DA/C is not. Try this URL http://abbreviations.wordcrow.com/define/DA%2FC/ and you would end up with http://abbreviations.wordcrow.com/define/DA/C/ which is an error page.

I can extend more code to recognize /define/DA/C/ but it's just weird and non-sensible. I tried both Chrome and Firefox and they all automatically convert DA%2FC to DA/C. But with DA%26E, they don't.

What am I doing wrong?

Oscar Mederos
  • 29,016
  • 22
  • 84
  • 124
datasn.io
  • 12,564
  • 28
  • 113
  • 154
  • possible duplicate of [Is a slash ("/") equivalent to an encoded slash ("%2F") in the path portion of an HTTP URL](http://stackoverflow.com/questions/1957115/is-a-slash-equivalent-to-an-encoded-slash-2f-in-the-path-portion-of-an) – wimvds May 18 '11 at 07:57
  • You're doing URL rewriting on the server side, like `^/define/(.+)$ => definition.php?term=$1`, right? – Salman A May 18 '11 at 08:12
  • 1
    http://httpd.apache.org/docs/2.2/mod/core.html#allowencodedslashes could help when using Apache... But why are you using the names as-is instead of creating a slug (http://debuggable.com/posts/title-to-url-slug-conversion:480f4dd6-a398-4c76-895c-4844cbdd56cb) for them? – wimvds May 18 '11 at 08:26
  • @wimvds, I just want to experiment a little bit on this one, all my other sites are using slugs. I tried to add "AllowEncodedSlashes On" in .htaccess but it doesn't work AND other pages give Internal Server Error. Would really like to know how to do this, cause' there are other acronyms sites that can do this and they are not using slugs. – datasn.io May 18 '11 at 09:57
  • @Salman A, no I'm not. I'm using $req = explode('/', $_SERVER['REQUEST_URI']); – datasn.io May 18 '11 at 09:57
  • @kavoir: `$req = explode('/', '/define/DA/C/', 3);` gives you `['', 'define', 'DA/C/']`. Will that help? – Salman A May 18 '11 at 11:25

1 Answers1

1

While you need to do what you need to do -

An option i finally used when AllowEncodedSlashes On didn't work was found here... (using slugs) - not only faster on the lookup/creation of them, but it [main point] solved my situation faster and had more 'url juice' :).

Found originally here:

http://snipplr.com/view/2809/convert-string-to-slug/

Used the modified here [used in my own files]:

http://www.finalwebsites.com/forums/topic/convert-string-to-slug

Bill Ortell
  • 837
  • 8
  • 12