[英]Inserting a hash before a directory name with Apache mod_rewrite or PHP?
I have a URL that is like the following: 我有一个如下网址:
http://www.example.com/client/project/subdirectory/value/
I would like like a simple way to be able to change/redirect the URL to the following: 我想要一种简单的方法来将URL更改/重定向到以下内容:
http://www.example.com/client/project/#/subdirectory/value/
Once the redirect is complete, the hash needs to be accessible via JavaScript. 重定向完成后,需要通过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: 换句话说,当网站上线时,URL的结构将有所不同,因此:
http://www.example.com/subdirectory/value/
Will change to: 将更改为:
http://www.example.com/#/subdirectory/value/
Edit: 编辑:
I have tried using this: RewriteRule ^profile/?$ #/profile/ [ NC,L] 我尝试使用此方法:RewriteRule ^ profile /?$#/ profile / [NC,L]
Which doesn't seem to do anything 哪个似乎什么都没做
Also tried this: RewriteRule ^profile/?$ /#/profile/ [NC,L] 还尝试了以下操作:RewriteRule ^ profile /?$ /#/ profile / [NC,L]
Which takes me to the root directory 这将我带到根目录
Also tried this: RewriteRule ^profile/?$ #/profile/ [R,NC,L] 还尝试了以下操作:RewriteRule ^ profile /?$#/ profile / [R,NC,L]
Which adds the whole root path to the server, followed by /%23/profile/ 它将整个根路径添加到服务器,然后是/%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/
Place a .htaccess
file into the directory of tests/redir
with the following: 使用以下命令将.htaccess
文件放入tests/redir
目录中:
RewriteEngine On
RewriteBase /tests/redir
RewriteRule ^(.*/)$ #/$1 [R,L,NE]
And you will get the wanted redirect. 然后,您将获得所需的重定向。 The R
flag plays together with the RewriteBase
directive. R
标志与RewriteBase
指令一起使用。 Also the NE
flag is necessary so that you can put #
literally into the redirect URI. 另外, NE
标志也是必需的,以便您可以将#
从字面上放入重定向URI。
The hash is already used by page anchor tags. 哈希已被页面定位标记使用。 You might need to replace it with an entity or pick a better character. 您可能需要用实体替换它或选择一个更好的字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.