dongzan7016 2011-05-18 07:45
浏览 619
已采纳

如何在URL中传递斜杠/?

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?

  • 写回答

1条回答 默认 最新

  • douxing8855 2011-08-05 13:00
    关注

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 名为“Product”的列已属于此 DataTable
  • ¥15 安卓adb backup备份应用数据失败
  • ¥15 eclipse运行项目时遇到的问题
  • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
  • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题