的.htaccess与片段重定向

编程入门 行业动态 更新时间:2024-10-25 04:18:44
本文介绍了的.htaccess与片段重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

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

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

例如:

www.exameple/test?foo=bar

应成为

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

或从URL以片段:

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

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

重写规则/测试www.example/#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:

www.exameple/test?foo=bar

should become

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

or taking the fragment from the url:

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

My (non-working) code looks like this:

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

解决方案

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

RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} /test RewriteRule ^test/?(.*)$ $1 [C] RewriteRule ^(.*)$ %{HTTP_HOST}/$1?%{QUERY_STRING}#MYVALUE [NE,L,R] RewriteCond %{HTTPS} on RewriteCond %{REQUEST_URI} /test RewriteRule ^test/?(.*)$ $1 [C] RewriteRule ^(.*)$ %{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与片段重定向

本文发布于:2023-11-01 23:24:24,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550707.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:片段   重定向   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!