插入一个哈希与Apache的mod_rewrite或PHP目录名前? [英] Inserting a hash before a directory name with Apache mod_rewrite or PHP?

查看:195
本文介绍了插入一个哈希与Apache的mod_rewrite或PHP目录名前?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个URL,它是这样的:

I have a URL that is like the following:

http://www.example.com/client/project/subdirectory/value/

我想就像一个简单的方法能够改变/重定向的URL,如下:

I would like like a simple way to be able to change/redirect the URL to the following:

http://www.example.com/client/project/#/subdirectory/value/

在重定向完成,哈希需要通过JavaScript访问。我没事了完全刷新/重定向,只是我写这一次,不必再改变它理想的。

Once the redirect is complete, the hash needs to be accessible via JavaScript. I'm okay with a full refresh/redirect, just ideally that I write this once and don't have to change it again.

在换句话说,当网站开始运行时,网址将被不同地构造,以便:

In other words, when the site goes live, the URLs will be structured differently, so that:

http://www.example.com/subdirectory/value/

将变为:

http://www.example.com/#/subdirectory/value/

编辑:

我一直在使用这种尝试:
     重写规则^资料/?$#/型材/ [NC,L]

I have tried using this: RewriteRule ^profile/?$ #/profile/ [ NC,L]

这似乎并没有做任何事情。

Which doesn't seem to do anything

也试过这样:
    重写规则^资料/?$ /#/型材/ [NC,L]

Also tried this: RewriteRule ^profile/?$ /#/profile/ [NC,L]

这需要我的根目录

也试过这样:
    重写规则^资料/?$#/型材/ [R,NC,L]

Also tried this: RewriteRule ^profile/?$ #/profile/ [R,NC,L]

这增加了整个根路径到服务器,随后/%23 /信息/

Which adds the whole root path to the server, followed by /%23/profile/

推荐答案

如果您有类似下面的网址:

If you have a URL like the following:

http://localhost/tests/redir/subdirectory/value/

和你想要得到它重定向到:

And you want to get it redirected to:

http://localhost/tests/redir/#/subdirectory/value/

的.htaccess 文件到的目录测试/ REDIR 通过以下内容:

Place a .htaccess file into the directory of tests/redir with the following:

RewriteEngine On
RewriteBase /tests/redir
RewriteRule ^(.*/)$ #/$1 [R,L,NE]

,你会得到想要的重定向。在研究标记与的RewriteBase 指令一起玩。另外, NE 标记是必要的,这样你可以把字面上到重定向URI。

And you will get the wanted redirect. The R flag plays together with the RewriteBase directive. Also the NE flag is necessary so that you can put # literally into the redirect URI.

这篇关于插入一个哈希与Apache的mod_rewrite或PHP目录名前?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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