允许斜杠URL的.htaccess [英] allow slash in url .htaccess

查看:185
本文介绍了允许斜杠URL的.htaccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个网页设置,用户可以浏览到某个项目,像这样在页面上:

I have a webpage set up where the user can navigate to a certain item on the page like so:

www.example.com/models.php#DDD-34

目前,它使用了符号来表示我要链接到该项目的code。使用的.htaccess允许 / 符号,而不是没有可能的

At the moment it uses a # symbol to indicate the code of the item i want to link to. Would it be possible using .htaccess to allow a / symbol instead of the #

因此​​,而不是上面的链接到一个项目的

So instead of the above to link to a item its

www.example.com/models.php/DDD-34

这将是可能的呢?因为 / 意味着它带来了一个路径要喝404错误。什么样的.htaccess code会允许这样做?

Would this be possible in anyway? Because / means a path it brings sup a 404 error. what .htaccess code would allow this?

推荐答案

您可以添加这样的事情在你的.htaccess文件:

You can add something like this in your .htaccess file:

RewriteEngine On
RewriteRule ^models.php/(.*)$   /models.php?item=$1    [L,NC,QSA]

然后有一个服务器端脚本(比方说,PHP)填写导航到锚需要的JavaScript:

Then have a server side script (let's say PHP) fill in the javascript needed to navigate to that anchor:

<script> location.hash = "#" + <?=$_GET['item'];?>; </script>

其中,&LT; = $ _ GET ['项目'];?&GT; 将会使用PHP添加的项目。 (注:如果使用PHP,你会想,以进一步保护那块code像这样的东西:<?code>&LT; =和addslashes($ _ GET ['项目']);&GT;

Where <?=$_GET['item'];?> will add the item using PHP. (Note: if using PHP, you would want to further protect that piece of code with something like this: <?=addslashes($_GET['item']);?>

或者,您可以使用乔恩林的回答结合使用的 <一个href="http://stackoverflow.com/questions/298503/how-can-you-check-for-a-hash-in-a-url-using-javascript">javascript抢散列项 <一个href="http://stackoverflow.com/questions/352343/is-there-a-way-to-change-the-browsers-address-bar-without-refreshing-the-page">HTML5's pushstate ,以达到你想要的东西,而无需使用服务器端脚本。

Alternatively, you could use Jon Lin's answer combined with using javascript to grab the hash item and HTML5's pushstate to achieve what you want without using a server side script.

这篇关于允许斜杠URL的.htaccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆