Membership is FREE – with unlimited access to all features, tools, and discussions. Premium accounts get benefits like banner ads and newsletter exposure. ✅ Signature links are now free for all. 🚫 No AI-generated (LLM) posts allowed. Share your own thoughts and experience — accounts may be terminated for violations.

How to pass slash / in an URL?

Status
Not open for further replies.

DataSN.com

Level 4
Legacy Exclusive Member
Joined
Oct 5, 2010
Messages
116
Reaction score
7
On this page there are many abbreviation / acronym entries: http://abbreviations.wordcrow.com/acronyms/D/

They are generated in PHP:

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&E/

Would first be fed to rawurldecode():

PHP:
$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/C/ 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? Ain't that / already encoded into '%2F'?? Really weird. Any help would be appreciated!
 

DataSN.com

Level 4
Legacy Exclusive Member
Joined
Oct 5, 2010
Messages
116
Reaction score
7
Thanks, RobM. Here's the .htaccess in the /define/ directory:

Code:
<IfModule mod_rewrite.c>

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]

</IfModule>

And in /define/index.php:

Code:
$req = explode('/', $_SERVER['REQUEST_URI']);

$acronym = rawurldecode($req[2]);

... // Database queries with $acronym

I tried to add "AllowEncodedSlashes On" in the .htaccess but it didn't work. Any idea?
 

ukbackorder

ukbackorder.com
Legacy Exclusive Member
Joined
Oct 12, 2003
Messages
1,609
Reaction score
644
I believe 'AllowEncodedSlashes On' has to actually be implemented at server level in the apache config file. So if this is not your server you'll have to ask the owning company to do it (they might refuse as some people believe it's not secure).
 
Status
Not open for further replies.

Who has viewed this thread (Total: 1) View details

The Rule #1

Do not insult any other member. Be polite and do business. Thank you!

Members Online

Premium Members

Upcoming events

Latest Listings

Our Mods' Businesses

*the exceptional businesses of our esteemed moderators

Top Bottom