[英]i need to redirect all page except for 1 page with POST data
我需要將請求重定向到舊域到新域,同時將頁面保留在舊域中。
編輯:簡而言之,所有具有發布數據的.json都將重定向到新域,除了1頁
如果可能的話,我該如何完成呢? 我使用提琴手在原始視圖中進行調試
重定向之前(使用.htaccess方法)
POST http://old.com/data.json HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.1.2; GT-N7105 Build/JZO54K)
Host: old.com
Connection: Keep-Alive
Accept-Encoding: gzip
Content-Length: 100
session=gVgr30Erxf03cDaA&store_version=9203b&inventory_version=123
重定向后
GET http://new.com/data.json HTTP/1.1
Content-Type: application/x-www-form-urlencoded
User-Agent: Dalvik/1.6.0 (Linux; U; Android 4.1.2; GT-N7105 Build/JZO54K)
Host: new.com
Connection: Keep-Alive
Accept-Encoding: gzip
在mod_rewrite中使用.htaccess
RewriteEngine On
RewriteRule ^page\.json$ - [L]
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule ^(.*\.json)$ http://newdomain.com/$1 [R=307,QSA]
[L]
不要更改。 [R=307]
到http://newdomain.com/ {page}的內容進行數學運算。 還要添加任何URL參數[QSA]
。 .htaccess
RewriteEngine On
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule ^$ http://test.jasny.net/redirect/posthere.php [R=307,QSA]
index.html
<form action="/redirect/" method="POST">
<input type="text" name="test">
<button type="submit">Submit</button>
</form>
posthere.php
<?
var_dump($_POST);
我同意arnold,.htaccess,但如果您只希望使用$ _POST數據進行請求,那么我將創建一個處理請求的小型php文件,測試是否包含發布,然后重定向到您的舊域,如果不重定向到新域
.htaccess
RewriteCond %{REQUEST_METHOD} =POST
RewriteRule ^foo/bar$ http%1://www.example.com%{REQUEST_URI} [L,R=301]
或將所有流量重定向到php文件,然后執行以下操作:
if( count( $_POST ) < 1 ) {
header( "HTTP/1.0 301 Moved Permanently" );
header( "Status: 301" );
header( "Location: http://".CLIENT_DOMAIN."{$_SERVER['REQUEST_URI']}");
die();//or exit;
}else{////same}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.