问候,
我刚刚将一个网站从IIS移动到Apache,并且在重定向索引文件时遇到一些麻烦,而不会导致无限循环.
这两者都将导致循环 -
重定向301 /index.htm /index.php
重定向301 /index.htm http://www.foo.com/
下面是我当前.htaccess的副本.有人能帮我吗?我有一堆指向http://www.foo.com/index.htm的链接,我想将301重定向到http://www.foo.com/
RewriteEngine On
########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying …Run Code Online (Sandbox Code Playgroud) 好的,我知道最佳做法是,一旦您更改或删除页面URL,将该URL重定向到新的相关URL.
但是持续多久?永远?
例如,我使用Google网站优化工具来测试网页的不同变体.所以我必须为每个创建一个不同的url:original.php,var1.php,var2.php等.
一旦测试完成,获胜者将成为新的original.php,并且不需要保留var1.php等.但我现在需要将那些不再需要的URL重定向到相关的original.php.
这可能最终导致我的.htaccess文件中有301个重定向.我也听说你的.htaccess文件中的东西越多,你的网站变得越慢,因为服务器必须先处理其中的所有内容才能提供一个页面.
我可以将重定向移动到实际的URL(例如实际的var1.php文件上的php重定向)但是我有几个不需要的文件膨胀我的服务器.
所以我想知道这里最好的做法是什么?这么长时间后删除301重定向是否安全?
我学会了Connection: close在Java中进行301重定向时使用
response.setStatus(301);
response.setHeader("Location", "http://www.example.com/");
response.setHeader("Connection", "close");
Run Code Online (Sandbox Code Playgroud)
我们为什么要做这个?为什么不省略最后一行?
我在至少三个例子中看到了这一点,包括这个例子:http://www.pardontheinformation.com/2010/09/java-servlet-jsp-301-and-302-redirect.html
我从未见过最后一行省略.
我们正在实施一个短网址服务,其中重定向目标将每天更改.网址将由移动设备访问,并始终是GET请求.我试图了解哪种是最适合工作的300型重定向.
AFAIK大多数网址缩短服务使用301重定向(永久移动).但是,根据规格,303(见其他)和307(暂时移动)重定向似乎是为我们的案例设计的......
redirect http url-shortener http-status-code-301 http-status-code-307
我创建了以下PHP函数到网页的HTTP代码.
function get_link_status($url, $timeout = 10)
{
$ch = curl_init();
// set cURL options
$opts = array(CURLOPT_RETURNTRANSFER => true, // do not output to browser
CURLOPT_URL => $url, // set URL
CURLOPT_NOBODY => true, // do a HEAD request only
CURLOPT_TIMEOUT => $timeout); // set timeout
curl_setopt_array($ch, $opts);
curl_exec($ch); // do it!
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE); // find HTTP status
curl_close($ch); // close handle
return $status;
}
Run Code Online (Sandbox Code Playgroud)
如何修改此功能以遵循301和302重定向(可能的多重定向)并获取最终的HTTP状态代码?
我们正在用 PHP 开发一个 URL 缩短器项目。我们使用 301 HTTP 重定向并自然地跟踪我们的链接访问。但有一些奇怪的事情:
我们缩短了一个网址,通过浏览器通过后,只跟踪了第一次访问,好像没有其他请求发送到我们的服务器,直接转到目标网址。(我认为这是浏览器缓存之后一试)。但 :
当尝试使用类似bitly 的服务时,它有不同的待遇。相同浏览器上的一些相同请求在位访问跟踪中被跟踪(实际上不止一个,我不明白为什么,我没有看到任何逻辑),同时它们也使用 301 重定向。(在左边浏览器窗口的底部有时会写“waiting for bit.ly...”,有时不会,实际上是随机的)。
这里包含任何技巧吗?这种不同的待遇会发生什么?
将所有页面从旧域移动到新域时,我注意到有些人添加了 ^ 而其他不在 rewriterule 中
之间有什么不同
RewriteRule ^(.*)$ http://mynewdomain.com/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
和
RewriteRule (.*)$ http://mynewdomain.com/$1 [R=301,L]
Run Code Online (Sandbox Code Playgroud)
谢谢你。
我需要能够浏览到http://www.example.com/index.php,但 WordPress 会自动 301 将其重定向到http://www.example.com/。
是否可以仅针对主页停止此重定向?
这是我的 .htaccess 文件:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Run Code Online (Sandbox Code Playgroud) php wordpress .htaccess http-status-code-301 url-redirection
我想让浏览器缓存重定向的响应。
我将标签src上的属性设置img为重定向到最终资源的 url。重定向仅在短时间内有效(例如 15 分钟),但下载的实际内容是长期有效的(即可以安全地存储一年)。我正在设置Cache-Control: max-age: <1 year>图像响应,但是由于重定向只能使用 15 分钟,所以我设置了Cache-Control: max-age: <15 minutes>. 我怎样才能告诉浏览器使用最终响应的缓存设置,甚至不必在后续页面视图中遵循重定向?
3XX我使用什么类型的重定向 ( ) 有关系吗?
这与:Chrome 和 Safari 缓存 302 重定向有关,但我实际上希望他们将其视为错误。
http http-caching browser-cache http-status-code-301 http-status-code-302
我们最近迁移到 SSL,除了一项功能外,该站点运行良好。该函数在下面的代码中使用 curl 来执行位于同一服务器上的 api。这个函数的url变量是:news.hubsdev.com/administrator/index.php?option=com_api&task=acymailing.listcreate $ch变量是-resource id='384' type='curl'
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_COOKIE, session_name() . '=' . session_id());
curl_setopt($ch, CURLOPT_POST, count($data));
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
Run Code Online (Sandbox Code Playgroud)
回应是
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<<title>301 Moved Permanently</title>
</head><body>
<h1>Moved Permanently</h1>
<p>The document has moved <a href="https://news.hubsdev.com/administrator/index.php?option=com_api&task=acymailing.listcreate">here</a>.</p>
</body></html>
Run Code Online (Sandbox Code Playgroud)
我们使用的是 AWS 上托管的 PHP 5.6 版。我测试了 ssl 证书并通过了“A”。
如何确定我收到此错误的原因?
谢谢!肯
redirect ×6
php ×4
http ×3
.htaccess ×2
curl ×2
mod-rewrite ×2
apache ×1
http-caching ×1
java ×1
wordpress ×1