的.htaccess与片段重定向 [英] .htaccess redirect with fragment

查看:188
本文介绍了的.htaccess与片段重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要发出重定向,使用。htaccess,与一个片段(也称为锚)的URL,但它自动转义#

目前,我希望有一个硬codeD片段,而是为他人着想,如果你知道如何利用它的URL也将是一件好事。

理想我应该能够使用QSA以及

例如:

  http://www.exameple.com/test?foo=bar
 

应成为

  1)http://www.example.com/?foo=bar#MYVALUE
 

或从URL以片段:

  2)http://www.example.com/?foo=bar#test
 

我的(非工作)code是这样的:

 重写规则/测试http://www.example.com/#MYVALE [R,QSA]
 

解决方案

我想我已经想通弄明白了......

 的RewriteCond%{} HTTPS关闭
的RewriteCond%{REQUEST_URI} /测试
重写规则^测试/?(.*)$ $ 1 [C]
重写规则^ $ HTTP(*)://%{HTTP_HOST} / $ 1%{QUERY_STRING} #MYVALUE [NE,L,R]

的RewriteCond%{} HTTPS上
的RewriteCond%{REQUEST_URI} /测试
重写规则^测试/?(.*)$ $ 1 [C]
重写规则^ $ HTTPS(*)://%{HTTP_HOST} / $ 1%{QUERY_STRING} #MYVALUE [NE,L,R]
 

这是一个有点差不必做一次HTTP和再次HTTPS - 我去看看能不能找到办法解决

I need to issue a redirect, using .htaccess, to a URL with a fragment (also known as an anchor), but it's automatically escaping the #.

At the moment I want a hard-coded fragment, but for the sake of others if you know how to take it from the URL too that would be good.

Ideally I should be able to use QSA as well.

For example:

http://www.exameple.com/test?foo=bar

should become

1) http://www.example.com/?foo=bar#MYVALUE

or taking the fragment from the url:

2) http://www.example.com/?foo=bar#test

My (non-working) code looks like this:

RewriteRule /test http://www.example.com/#MYVALE [R,QSA]

解决方案

I think I've got it figured out...

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} /test
RewriteRule ^test/?(.*)$ $1 [C]
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1?%{QUERY_STRING}#MYVALUE [NE,L,R]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} /test
RewriteRule ^test/?(.*)$ $1 [C]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1?%{QUERY_STRING}#MYVALUE [NE,L,R]

It's a bit poor having to do it once for HTTP and again for HTTPS - I'll see if I can find a way around that.

这篇关于的.htaccess与片段重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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