基于RFC,似乎302响应中的位置字段应该是绝对的. http://tools.ietf.org/html/rfc2616#section-14.30
如果这个陈述是正确的,浏览器是否尊重这个 - 或者他们是否允许相对路径?
出于某种原因,非IE浏览器似乎在发送服务器端重定向(使用Location头)时保留URL哈希(如果存在).例:
// a simple redirect using Response.Redirect("http://www.yahoo.com");
Text.aspx
Run Code Online (Sandbox Code Playgroud)
如果我访问:
Test.aspx#foo
Run Code Online (Sandbox Code Playgroud)
在Firefox/Chrome中,我被带到:
http://www.yahoo.com#foo
Run Code Online (Sandbox Code Playgroud)
谁能解释为什么会这样?我已经在不同的平台上尝试了各种服务器端重定向(虽然所有这些都导致了Location头),但这似乎总是发生.我没有在HTTP规范中看到它,但它似乎确实是浏览器本身的问题.URL哈希(如预期的那样)永远不会发送到服务器,因此服务器重定向不会被它污染,浏览器只是出于某种原因持久化它.
有任何想法吗?
我想重写http://example.com/articles.html#first-article与http://example.com/articles/first-article
有可能重写吗?
我尝试使用以下但不适合我:
RewriteRule ^articles/(.+)$ /articles\.html\#$1
Run Code Online (Sandbox Code Playgroud) 我有一个基本链接:
<a href="https://pieworld.com/apple#1/" target="_blank">Free Pie Here</a>
但当我点击它时,我被重定向到 https://pieworld.com/apple
哈希标记之后的所有内容以及哈希都不包括在内.这只发生在IE10中.我已经测试过没有那个target="_blank",但链接仍然在哈希中断.
似乎无法找到任何关于此的文档.我最接近的是这个问题,但它没有帮助.
一些可能有用的背景信息:
这是一个.Net站点
我正在从http:一个https:站点重定向到一个站点.
在我的Rails论坛应用程序中,当在主题中创建新帖子时,它将重定向到topic_path,其中包含页面索引和锚点的附加参数,以便滚动到帖子.像这样:
应用程序/控制器/ posts_controller.rb
def create
@topic = Topic.find(params[:topic_id])
@post = @topic.posts.build(post_params.merge({user_id: current_user.id}))
if @post.save
flash[:success] = "Post Created"
redirect_to topic_path(@topic, :page => @post.page, :anchor => @post.anchor)
else
render 'new'
end
end
Run Code Online (Sandbox Code Playgroud)
重定向后的URL是: http://localhost:3000/topics/1?page=3#post-1364
但是我在Posts控制器的Show动作中做同样的事情.由于我不想自己显示帖子,因此该操作只需使用页面索引和帖子锚定重定向到主题.
应用程序/控制器/ posts_controller.rb
# Post are not displayed on their own. Showing one will jump to the post inside its topic
def show
post = Post.find(params[:id])
redirect_to topic_path(post.topic, :page => post.page, :anchor => post.anchor)
end
Run Code Online (Sandbox Code Playgroud)
但是为帖子调用show方法后的url不包含锚点.它确实包括页面:http://localhost:3000/topics/1?page=3
我调试了show方法,post.anchor正在被正确解析.
我的终端输出显示锚由于某种原因丢失
Started GET "/posts/1364" for 127.0.0.1 at 2014-08-13 10:03:31 …Run Code Online (Sandbox Code Playgroud) 显然,散列之后的所有内容都称为“编码片段”。Uri.getEncodedFragment() 返回此字符串。
我的用例是这样的。给定一个网址:
url = "https://first/#/second"
Run Code Online (Sandbox Code Playgroud)
如果我做:
webView.loadUrl(url);
Run Code Online (Sandbox Code Playgroud)
WebView 删除哈希符号后的所有内容,使用修改后的 URL 发出请求:“ https://first/ ”
关于如何在请求中传递完整 URL 的任何想法?
编辑:
我认为这与一个众所周知的重定向问题有关: URL Fragment and 302 redirects
任何人都有任何适用于Android的解决方案?
可能重复:
URL片段和302重定向
我正在将Facebook登录信息集成到我的网站中。当Facebook使用代码查询参数重定向到我的网站时,末尾会有一个哈希。http://myurl.com/code=xxx#_=_
然后,当我从该URL重定向到我的网站的另一个URL时:
header('Location: http://myurl.com/home');
Run Code Online (Sandbox Code Playgroud)
它保留哈希标签并最终显示为 http://myurl.com/home#_=_
有没有没有哈希的重定向方法,或者如果有人熟悉Facebook,有没有办法让它首先停止添加哈希?
出于某种原因,当我使用header("Location")新页面重定向时保留哈希值.
所以,如果你在 example.com/index.html#signup
我重定向
header("Location: /account.html");
exit;
Run Code Online (Sandbox Code Playgroud)
但它表明了 example.com/account.html#signup
为什么会这样,我怎么能阻止它呢?即example.com/account.html
注意:
我正在使用.htaccess重定向file.html到file.php
RewriteRule ^([a-zA-Z0-9-_.]+)\.html$ $1.php [L]
Run Code Online (Sandbox Code Playgroud) 我目前正在通过获取一个变量并将其插入新 URL 来重定向 URL。像这样:
RewriteCond %{QUERY_STRING} &pid=([0-9]*)$
RewriteRule ^vault/displayimage\.php$ photos/%1/? [R=301,L]
Run Code Online (Sandbox Code Playgroud)
不幸的是,有些链接在旧系统中有一个不需要的主题标签,所以我想在没有它们的情况下重定向(或剥离它们)。前任。- 通过上面的重定向,我们采取类似
/vault/displayimage.php?album=5&pid=10#top_pictures
Run Code Online (Sandbox Code Playgroud)
重定向到
/photos/10/#top_pictures
Run Code Online (Sandbox Code Playgroud)
我希望它只是
/photos/10/
Run Code Online (Sandbox Code Playgroud)
感谢您提供任何提示!
我一直在使用Django的auth模块,但最近不得不关闭它.auth模块通过重定向到登录页面并将您从中注销的页面设置为?next=/currentPage参数来处理会话过期.
因此,如果我的会话到期,#dashboard我将被重定向到:
mydomain/account/login?next=/#dashboard
Run Code Online (Sandbox Code Playgroud)
离开Django auth模块后,我注意到这已经改为:
mydomain/account/login/#dashboard
Run Code Online (Sandbox Code Playgroud)
这看起来与我理解它在阅读URL Fragment和302重定向后应该起作用的方式一致,但是,我想操纵这个片段但是在我的HttpResponse对象中没有看到它.
django.contrib.auth使用以下函数来处理此请求,但我看不到它们移动片段的位置.实际上我只是想完全删除片段,但如果我不能,我会满足于将它放回?next=参数中.
def user_passes_test(test_func, login_url=None, redirect_field_name=REDIRECT_FIELD_NAME):
"""
Decorator for views that checks that the user passes the given test,
redirecting to the log-in page if necessary. The test should be a callable
that takes the user object and returns True if the user passes.
"""
def decorator(view_func):
@wraps(view_func, assigned=available_attrs(view_func))
def _wrapped_view(request, *args, **kwargs):
if test_func(request.user):
return view_func(request, *args, **kwargs)
path = request.build_absolute_uri() …Run Code Online (Sandbox Code Playgroud) 客户要求我自动将任何带有英镑符号的网址重定向到没有英镑符号的版本,但我不认为我在使用此公式的任何网址中检测到#.我使用curPageURL()公式通过电子邮件向自己发送了一个示例网址,它在我测试的网址中没有包含尾随的#符号.
function curPageURL() {
$pageURL = 'http';
if ($_SERVER["HTTPS"] == "on") {$pageURL .= "s";}
$pageURL .= "://";
if ($_SERVER["SERVER_PORT"] != "80") {
$pageURL .= $_SERVER["SERVER_NAME"].":".$_SERVER["SERVER_PORT"].$_SERVER["REQUEST_URI"];
} else {
$pageURL .= $_SERVER["SERVER_NAME"].$_SERVER["REQUEST_URI"];
}
return $pageURL;
}
if(stripos($currenturl,'#'))
{
Header( "HTTP/1.1 301 Moved Permanently" );
$location = 'Location: ' . str_replace('#','',$currenturl) . '/';
Header($location);
}
Run Code Online (Sandbox Code Playgroud)
*更正 - 我在标题的最后说,我的意思是结束,我的代码在这里可以检测到网址中任何地方的英镑符号.*
嗨,我正在尝试使用本教程在我的网站上实现一个简单的联系表单 - http://rosstanner.co.uk/2012/11/build-simple-contact-form-html-php-bootstrap/
麻烦在用户提交动作后我需要将用户重定向到页面底部的锚ID,即www.somepage.com/index.php#contact
重定向就是这个......
header('Location: index.php?s='.urlencode('Thank you for your message.'))
Run Code Online (Sandbox Code Playgroud)
我试过了...
header('Location: index.php?s='.urlencode('Thank you for your message.')'#contact')
Run Code Online (Sandbox Code Playgroud)
......但无济于事.
当我尝试添加这样的内容以使其向下滚动到锚标签时,浏览器会挂在contact-form-submission.php页面上(联系表单逻辑的单独php页面)
如果我在复杂的情况下解释了这一点,我很抱歉.我其实不懂PHP!