我想将常见的URL重定向到哈希URL,如下所示,
http://localhost/mywebsite/estate/heritage/
至
http://localhost/mywebsite/#/estate/heritage/
我的.htaccess中有这个重写代码,
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ #/$1/$2/ [R,L,NE]
但是我得到的结果是
http://localhost/C:/wamp/www/mywebsite/#/estate/heritage/
它有多余的C:/wamp/www/
我不想要的。
我该如何删除它,或者如何不在我的重写代码中打印它?
您可以将此规则放在/mysaite/.htaccess
:
RewriteEngine On
# set ENV variable BASE equal to current RewriteBase value dynamically
RewriteCond %{REQUEST_URI}::$1 ^(.*?/)(.*)::\2$
RewriteRule ^(.*)$ - [E=BASE:%1]
RewriteRule ^([a-z0-9-]+)/([a-z0-9-]+)/?$ %{ENV:BASE}#/$1/$2/ [L,NC,NE,R=302]
使用RewriteBase
对于解决您陈述的问题非常重要。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句