GVKun编程网logo

在Apache中使用htaccess重写HTTP GET请求到POST(apache重写规则)

22

如果您想了解在Apache中使用htaccess重写HTTPGET请求到POST和apache重写规则的知识,那么本篇文章将是您的不二之选。我们将深入剖析在Apache中使用htaccess重写HTT

如果您想了解在Apache中使用htaccess重写HTTP GET请求到POSTapache重写规则的知识,那么本篇文章将是您的不二之选。我们将深入剖析在Apache中使用htaccess重写HTTP GET请求到POST的各个方面,并为您解答apache重写规则的疑在这篇文章中,我们将为您介绍在Apache中使用htaccess重写HTTP GET请求到POST的相关知识,同时也会详细的解释apache重写规则的运用方法,并给出实际的案例分析,希望能帮助到您!

本文目录一览:

在Apache中使用htaccess重写HTTP GET请求到POST(apache重写规则)

在Apache中使用htaccess重写HTTP GET请求到POST(apache重写规则)

我需要改变第三方PHP应用程序的行为,并在稍后恢复更改。 如果我可以重写GET请求并将其发送出去,我会节省很多时间,并且可以避免在应用程序中进行任何更改。

是否有可能将GET http://website/action1?param=1转换为POST http://website/action2 , param是post请求的一部分,使用.htaccess?

虽然,我可以将第一个GET请求redirect到将自动POST(POST)到第二个URL的新页面,但是我希望保持尽可能低的浏览器与服务器交互数量。

mod_rewrite {QUERY_STRING}

Symfony从路由中移除前三个字符

.htaccess URL和目录redirect

.htaccess重写规则不会unicode字符

mod_rewrite的部分url为GEtvariables

Apache .htaccess隐藏.PHP和.html扩展名

使用.htaccess将一个特定的IP地址redirect到我的主页的特殊页面

htaccess重写规则不适用于以.cfm结尾的url

如何在PHP中显示Apache的默认404页面

Mod_rewrite将example.com/page.PHP?v1=abc&v2=def改为example.com/abc/def

是否有可能将GET http://website/action1?param=1转换为POST http://website/action2 ,param是post请求的一部分,使用.htaccess?

不,这是不可能的。 GET和POST是完全不同的请求,具有不同的请求标头和不同的响应。 重写引擎只影响URI,不能改变实际的请求。 你将不得不在浏览器端依靠Javascript。

总结

以上是小编为你收集整理的在Apache中使用htaccess重写HTTP GET请求到POST全部内容。

如果觉得小编网站内容还不错,欢迎将小编网站推荐给好友。

.htaccess重写GET变量

.htaccess重写GET变量

我有一个index.php,它处理所有路由index.php?page = controller(简体)只是为了与视图分离逻辑。

Options +FollowSymlinksRewriteEngine onRewriteCond %{REQUEST_FILENAME} !-fRewriteCond %{REQUEST_FILENAME} !-dRewriteRule ^([\w\d~%.:_\-]+)$ index.php?page=$1 [NC]

我无法与Rewriterule一起使用。

控制器可能如下所示:

    <?phpif (isset($_GET[''action''])) { if ($_GET[''action''] == ''delete'') {do_Delete_stuff_here();}}?>

并且:

    <?phpif (isset($_GET[''action'']) && isset($_GET[''x''])) { if ($_GET[''action''] == ''delete'') {do_Delete_stuff_here();}}?>

答案1

小编典典

基本上人们想说的是,您可以像这样编写重写规则:

RewriteRule ^(.*)$ index.php?params=$1 [NC, QSA]

这将使您的实际php文件如下所示:

index.php?params=param/value/param/value

您的实际网址如下所示:

http://url.com/params/param/value/param/value

在您的PHP文件中,您可以通过如下分解方式来访问参数:

<?php$params = explode( "/", $_GET[''params''] );for($i = 0; $i < count($params); $i+=2) {  echo $params[$i] ." has value: ". $params[$i+1] ."<br />";}?>

.htaccess重写规则强制将httpsredirect到http

.htaccess重写规则强制将httpsredirect到http

我有一个主域名https://www.domain.com或https://domain.com和像https://domain.com/index.PHP?name=abcd强制通过http://abcd.domain.comredirect的通配DNS http://abcd.domain.com但我有另一个问题,我的login页面是https://domain.com/login.PHP?name=abcd ,我想结果像强制http://domain.com/login.PHP?name=abcd但它不能在HTTP上redirect。

RewriteEngine On #match either the www subdomain or no subdomain RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain.com)$ #which request index.PHP RewriteCond %{REQUEST_URI} ^/index.PHP #and contain a username paramater RewriteCond %{QUERY_STRING} ^(.*?)(?:^|&)name=([^&]+)(.*?)$ #then rewrite them to name.domain.com without the name parameter RewriteRule ^ http://%1.domain.com%{REQUEST_URI} [R,L] #match either the www subdomain or no subdomain RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain.com)$ #which was requested without https RewriteCond %{HTTPS} off #then redirect to https RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R,L] #Capture subdomain RewriteCond %{HTTP_HOST} ^([^.]+).(?:domain.com)$ #If we're not working on www RewriteCond %{HTTP_HOST} !^(?:www.domain.com)$ #If querystring doesn't contain name RewriteCond %{QUERY_STRING} !^(.*?)(?:^|&)name=([^&]+)(.*?)$ #Add username to querystring RewriteRule index.PHP index.PHP?name=%1 [L,QSA]

这个htaccess的代码工作正常,但我想login脚本在htaccess

在聊天澄清后,这是我所需要的:

所有的URL都应该被重写为https ,除了login.PHP ,它应该停留在http 。 如果login.PHP以https ,请将其重写为http 。

请求的资源.htaccess上不存在Access-Control-Allow-Origin标头

mod_rewrite不适用于Windows 7上的Apache 2.2

Apache .htaccess隐藏.PHP和.html扩展名

如何使mod_rewrite从子域redirect到查询string?

如果不是带有apache的目录,则删除结尾的斜杠

我怎样才能设置CORS访问我的Linux Web服务器上的audio文件与Apache2?

在htaccess中禁用PHP函数

多国使用.htacces

无法获取.htaccess mod_rewrite规则工作 – 404找不到

.htaccess:如果调用特定的目录,则重写整个URL

你已经有重写为https的规则,唯一剩下的就是不包括login.PHP

RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain.com)$ RewriteCond %{HTTPS} off RewriteCond %{REQUEST_URI} !^/login.PHP$ RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

如果用 https请求login.PHP ,则将其重写为http

RewriteCond %{HTTP_HOST} ^(?:www.)?(?:domain.com)$ RewriteCond %{HTTPS} on RewriteRule ^login.PHP$ http://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

最后,一个小提示: 从不测试301启用,看到这个答案提示调试.htaccess重写规则的细节。

尝试这个 :

RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

Android使用Apache HttpClient发送GET、POST请求

Android使用Apache HttpClient发送GET、POST请求

简单的网页下载,HttpURLConnection可以完成,但是涉及到用户登录等权限相关问题,就需要涉及Session、Cookies。,就很难使用HttpURLConnection来处理了。Apache开源组织提供了一个HttpClient项目可以处理这些问题。HttpClient关注于如何发送请求、接受请求,以及管理HTTP链接。
使用HttpClient对象来发送请求、接受响应步骤:

  1. 创建HttpClient对象

  2. 如果要发送GET请求,创建HttpGet对象;如果是POST请求,则创建HttpPost对象。

  3. 如果需要添加参数,对于HttpGet直接在构造URL的时候填入参数。对于POST请求,使用setEntity(HttpEntity entity)方法来设置

  4. 调用HttpClient对象的execute(HttpUriRequest request)发送请求,此方法返回一个HttpResponse

  5. 调用HttpResponse的getALLHeaders()、getHeaders(String name)等方法可获取服务器响应头;调用HttpResponse的getEntity()方法可获取HttpEntity对象,该对象包装了服务器响应内容。

注意:

不少地方说可以使用HttpGet和HttpPost共同的setParams(HttpParams params)方法添加请求参数,但是我没有设置成功,网上搜索发现好多人也没成功。Even Apache’s official example uses URIBuilder’s setParameter method to build the params out in the URI,所以没有使用这种方法.

GET请求Demo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
public class MainActivity extends Activity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super .onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         TextView textViewShow = (TextView) findViewById(R.id.showText);
         //直接在URL后添加请求参数
         String url = "http://192.168.1.103/index.php?get1=hello&get2=bay" ;
         try {
             // 创建DefaultHttpClient对象
             HttpClient httpclient = new DefaultHttpClient();
             // 创建一个HttpGet对象
             HttpGet get = new HttpGet(url);
             // 获取HttpResponse对象
             HttpResponse response = httpclient.execute(get);
             //判断是否链接成功
             if (response.getStatusLine().getStatusCode() == 200 ) {
                 //实体转换为字符串
                 String content = EntityUtils.toString(response.getEntity());
                 textViewShow.setText(content);
             } else {
                 textViewShow.setText( "网络错误" );
             }
 
         } catch (ClientProtocolException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         } catch (IOException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
         }
     }
 
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         // Inflate the menu; this adds items to the action bar if it is present.
         getMenuInflater().inflate(R.menu.main, menu);
         return true ;
     }
}

POST请求Demo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
public class MainActivity extends Activity {
 
     @Override
     protected void onCreate(Bundle savedInstanceState) {
         super .onCreate(savedInstanceState);
         setContentView(R.layout.activity_main);
         TextView textViewShow = (TextView) findViewById(R.id.showText);
 
         String url = "http://192.168.1.103/index.php" ;
         HttpClient httpClient = new DefaultHttpClient();
         try {
         HttpPost post = new HttpPost(url);
         List params = new ArrayList();
         params.add( new BasicNameValuePair( "get1" , "hello" ));
         params.add( new BasicNameValuePair( "get2" , "usrl" ));
 
             post.setEntity( new UrlEncodedFormEntity(params, HTTP.UTF_8));
             HttpResponse response = httpClient.execute(post);
             if (response.getStatusLine().getStatusCode() == 200 ){
                 String content = EntityUtils.toString(response.getEntity());
                 textViewShow.setText(content);
 
             } else {
                 textViewShow.setText( "网络问题" );
             }
 
         } catch (UnsupportedEncodingException e) {
             // TODO Auto-generated catch block
             textViewShow.setText( "UnsupportedEncodingException" );
         } catch (ClientProtocolException e) {
             // TODO Auto-generated catch block
             textViewShow.setText( "ClientProtocolException" );
         } catch (IOException e) {
             // TODO Auto-generated catch block
             textViewShow.setText( "IOException" );
         }
 
     }
 
     @Override
     public boolean onCreateOptionsMenu(Menu menu) {
         // Inflate the menu; this adds items to the action bar if it is present.
         getMenuInflater().inflate(R.menu.main, menu);
         return true ;
     }
 
}


Android用Apache HttpClient 实现POST和Get请求

Android用Apache HttpClient 实现POST和Get请求

  1. Get实现

       java代码

package com.yarin.android.Examples_08_02;
import java.io.IOException;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Activity02 extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.http);
  TextView mTextView = (TextView) this.findViewById(R.id.TextView_HTTP);
  // http地址
  String httpUrl = "http://192.168.1.110:8080/httpget.jsp?par=HttpClient_android_Get";
  // HttpGet连接对象
  HttpGet httpRequest = new HttpGet(httpUrl);
  try {
   // 取得HttpClient对象
   HttpClient httpclient = new DefaultHttpClient();
   // 请求HttpClient,取得HttpResponse
   HttpResponse httpResponse = httpclient.execute(httpRequest);
   // 请求成功
   if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    // 取得返回的字符串
    String strResult = EntityUtils.toString(httpResponse
      .getEntity());
    mTextView.setText(strResult);
   } else {
    mTextView.setText("请求错误!");
   }
  } catch (ClientProtocolException e) {
   mTextView.setText(e.getMessage().toString());
  } catch (IOException e) {
   mTextView.setText(e.getMessage().toString());
  } catch (Exception e) {
   mTextView.setText(e.getMessage().toString());
  }
  // 设置按键事件监听
  Button button_Back = (Button) findViewById(R.id.Button_Back);
  /* 监听button的事件信息 */
  button_Back.setOnClickListener(new Button.OnClickListener() {
   public void onClick(View v) {
    /* 新建一个Intent对象 */
    Intent intent = new Intent();
    /* 指定intent要启动的类 */
    intent.setClass(Activity02.this, Activity01.class);
    /* 启动一个新的Activity */
    startActivity(intent);
    /* 关闭当前的Activity */
    Activity02.this.finish();
   }
  });
 }
}

 2.   Post实现

  java代码

 package com.yarin.android.Examples_08_02;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.HttpStatus;
import org.apache.http.NameValuePair;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.util.EntityUtils;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
public class Activity03 extends Activity {
 /** Called when the activity is first created. */
 @Override
 public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.http);
  TextView mTextView = (TextView) this.findViewById(R.id.TextView_HTTP);
  // http地址
  String httpUrl = "http://192.168.1.110:8080/httpget.jsp";
  // HttpPost连接对象
  HttpPost httpRequest = new HttpPost(httpUrl);
  // 使用NameValuePair来保存要传递的Post参数
  List<NameValuePair> params = new ArrayList<NameValuePair>();
  // 添加要传递的参数
  params.add(new BasicNameValuePair("par", "HttpClient_android_Post"));
  try {
   // 设置字符集
   HttpEntity httpentity = new UrlEncodedFormEntity(params, "gb2312");
   // 请求httpRequest
   httpRequest.setEntity(httpentity);
   // 取得默认的HttpClient
   HttpClient httpclient = new DefaultHttpClient();
   // 取得HttpResponse
   HttpResponse httpResponse = httpclient.execute(httpRequest);
   // HttpStatus.SC_OK表示连接成功
   if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK) {
    // 取得返回的字符串
    String strResult = EntityUtils.toString(httpResponse.getEntity());
    mTextView.setText(strResult);
   } else {
    mTextView.setText("请求错误!");
   }
  } catch (ClientProtocolException e) {
   mTextView.setText(e.getMessage().toString());
  } catch (IOException e) {
   mTextView.setText(e.getMessage().toString());
  } catch (Exception e) {
   mTextView.setText(e.getMessage().toString());
  }
  // 设置按键事件监听
  Button button_Back = (Button) findViewById(R.id.Button_Back);
  /* 监听button的事件信息 */
  button_Back.setOnClickListener(new Button.OnClickListener() {
   public void onClick(View v) {
    /* 新建一个Intent对象 */
    Intent intent = new Intent();
    /* 指定intent要启动的类 */
    intent.setClass(Activity03.this, Activity01.class);
    /* 启动一个新的Activity */
    startActivity(intent);
    /* 关闭当前的Activity */
    Activity03.this.finish();
   }
  });
 }
}

今天关于在Apache中使用htaccess重写HTTP GET请求到POSTapache重写规则的分享就到这里,希望大家有所收获,若想了解更多关于.htaccess重写GET变量、.htaccess重写规则强制将httpsredirect到http、Android使用Apache HttpClient发送GET、POST请求、Android用Apache HttpClient 实现POST和Get请求等相关知识,可以在本站进行查询。

本文标签: