使用Apache mod_rewrite或PHP在目录名之前插入哈希?
我的URL如下所示:使用Apache mod_rewrite或PHP在目录名之前插入哈希?,php,apache,mod-rewrite,Php,Apache,Mod Rewrite,我的URL如下所示: http://www.example.com/client/project/subdirectory/value/ http://www.example.com/client/project/#/subdirectory/value/ http://localhost/tests/redir/subdirectory/value/ RewriteEngine On RewriteBase /tests/redir RewriteRule ^(.*/)$ #/$1 [R
http://www.example.com/client/project/subdirectory/value/
http://www.example.com/client/project/#/subdirectory/value/
http://localhost/tests/redir/subdirectory/value/
RewriteEngine On
RewriteBase /tests/redir
RewriteRule ^(.*/)$ #/$1 [R,L,NE]
我想用一种简单的方法将URL更改/重定向到以下位置:
http://www.example.com/client/project/subdirectory/value/
http://www.example.com/client/project/#/subdirectory/value/
http://localhost/tests/redir/subdirectory/value/
RewriteEngine On
RewriteBase /tests/redir
RewriteRule ^(.*/)$ #/$1 [R,L,NE]
重定向完成后,需要通过JavaScript访问散列。我可以完全刷新/重定向,只是理想情况下我只写一次,不必再次更改
换句话说,当网站上线时,URL的结构将不同,因此:
http://www.example.com/subdirectory/value/
将更改为:
http://www.example.com/#/subdirectory/value/
编辑:
我试过使用这个:
重写规则^profile/?$#/profile/[NC,L]
这似乎没什么作用
我也试过:
重写规则^profile/?$/#/profile/[NC,L]
这会把我带到根目录
我也试过:
重写规则^profile/?$#/profile/[R,NC,L]
它将整个根路径添加到服务器,然后是/%23/profile/页面锚标记已经使用了散列。您可能需要将其替换为一个实体或选择一个更好的字符。页面锚标记已经使用了散列。您可能需要将其替换为实体或选择更好的字符。如果您有如下URL:
http://www.example.com/client/project/subdirectory/value/
http://www.example.com/client/project/#/subdirectory/value/
http://localhost/tests/redir/subdirectory/value/
RewriteEngine On
RewriteBase /tests/redir
RewriteRule ^(.*/)$ #/$1 [R,L,NE]
您希望将其重定向到:
http://localhost/tests/redir/#/subdirectory/value/
使用以下内容将.htaccess
文件放入测试/redir
目录中:
http://www.example.com/client/project/subdirectory/value/
http://www.example.com/client/project/#/subdirectory/value/
http://localhost/tests/redir/subdirectory/value/
RewriteEngine On
RewriteBase /tests/redir
RewriteRule ^(.*/)$ #/$1 [R,L,NE]
你会得到想要的重定向。
R
标志与RewriteBase
指令一起播放。此外,还需要NE
标志,以便您可以将#
逐字放入重定向URI。如果您有如下URL:
http://www.example.com/client/project/subdirectory/value/
http://www.example.com/client/project/#/subdirectory/value/
http://localhost/tests/redir/subdirectory/value/
RewriteEngine On
RewriteBase /tests/redir
RewriteRule ^(.*/)$ #/$1 [R,L,NE]
您希望将其重定向到:
http://localhost/tests/redir/#/subdirectory/value/
使用以下内容将.htaccess
文件放入测试/redir
目录中:
http://www.example.com/client/project/subdirectory/value/
http://www.example.com/client/project/#/subdirectory/value/
http://localhost/tests/redir/subdirectory/value/
RewriteEngine On
RewriteBase /tests/redir
RewriteRule ^(.*/)$ #/$1 [R,L,NE]
你会得到想要的重定向。
R
标志与RewriteBase
指令一起播放。另外,NE
标志是必需的,这样您就可以将#
按字面意思放入重定向URI。我用我尝试过的内容编辑了这个问题。我对非mod_重写解决方案持开放态度!我用我试过的方法编辑了这个问题。我对非mod_重写解决方案持开放态度!这正是我要找的。我不得不修改它,使它只对某个目录进行重定向,并传递所有子目录(RewriteRule^profile/(.*)$#/profile/$1[R,L,NE]),但这是完美的。非常感谢你!这正是我要找的。我不得不修改它,使它只对某个目录进行重定向,并传递所有子目录(RewriteRule^profile/(.*)$#/profile/$1[R,L,NE]),但这是完美的。非常感谢你!