我如何使用PHP /阿帕奇(mod_rewrite的)到网址重定向哈希标签? [英] How can I use PHP/Apache (mod_rewrite) to redirect URLs as hash tags?

查看:144
本文介绍了我如何使用PHP /阿帕奇(mod_rewrite的)到网址重定向哈希标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当像 A URL /歌曲/ 123 被直接命中,我想重写/该URL重定向到 /index.php#/songs / 123

When a URL like /songs/123 is directly hit, I want to rewrite/redirect that URL to /index.php#/songs/123.

我想使用的服务器要做到这一点不是创建重定向虚拟页更有效率。

I figure using the server to do this is more efficient than creating "dummy" pages that redirect.

例如,我使用jQuery.address到'抓'的< A /> 标记并追加其的href 作为哈希标签,让网站能够无缝导航,并浏览器历史记录保持精度。我还是想这些的HREF是有效链接到相应的内容然而,万一有人打开它在一个新的标签或相似的。

For example, I use jQuery.address to 'catch' any <a/> tags and append its href as a hash tag, allowing the site to be navigated seamlessly and have browser history maintain accuracy. I still want these hrefs to be valid links to the appropriate content however in case someone opens it in a new tab or similar.

推荐答案

尝试是这样的(在你的.htaccess):

Try something like this (in your .htaccess):

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^/songs/(.+)$ /index.php#/songs/$1 [R,L,NE]
</IfModule>

或者捕获任何一种比较极端的情况下,这不是一个文件/目录:

Or a more extreme case that captures anything that isn't a file/directory:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php#$1 [R,L,NE]
</IfModule>

这篇关于我如何使用PHP /阿帕奇(mod_rewrite的)到网址重定向哈希标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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