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 高德地图点聚合中Marker的位置无法实时更新
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办