我有一个网页设置,用户可以浏览到某个项目,像这样在页面上:
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像这样的东西:&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']);?>
或者,您可以使用乔恩林的回答结合使用的 javascript抢散列项 和 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.