Atitit. Implement reverse Proxy (1)----URL rewrite configuration and content rewrite and-absolute path link rewrite Java PHP

Source: Internet
Author: User
Tags abs

Atitit. Implement reverse Proxy (1)----URL rewrite configuration and content rewrite and-absolute path link rewrite Java PHP

1. Implementation of the Agent::: General agent and reverse agent?? 1

2. URL rewrite frame selection 1

3.---------Reverse Proxy rewrite configuration Mode_rewrite 1

1. Java Implementation 2

4. Excluding itself (Apache_mode_rewrite) 2

2. Java implementation excludes itself 2

5. Content Rewriting (PHP MODE_RWT) 3

3. Java Content Rewriting 3

6. Content Rewriting---Absolute path link rewrite 4

4. Abs URL 2/app/http://xxxxxx.jpg 4

5. Filter two times Navigation 4

6. Judge and replace rewrite 5

7. Quote 6

1. Implementation of the Agent::: General agent and reverse agent??

Common agent set up trouble, Korean reverse proxy easy to implement.

Reverse Proxy usage Process:: localhost/vod/>>url rewrite >>> content changes

2. URL Rewrite frame selection

PHP mode_rewrite Good ... java org.tuckey.web.filters.urlrewrite.UrlRewriteFilter not too good to use the,,, son good ga ...

Author:: Old Wow's paw Attilax Airon, email:1466519819@qq.com

Reprint please indicate the source: Http://blog.csdn.net/attilax

3. ---------reverse proxy rewrite configuration mode_rewrite

Rewritecond%{request_uri}!=/process.php

Rewriterule ^ (. *) $/process.php?file=http://www.budejie.com/$1&noext=1 [L] [l]

1. Java implementation

<!--o8j2-->

<filter>

<filter-name>urlrwt</filter-name>

<filter-class>com.attilax.net.urlRewriteFilterAti</filter-class>

</filter>

<filter-mapping>

<filter-name>urlrwt</filter-name>

<url-pattern>/*</url-pattern>

</filter-mapping>

<!--end O8j2-->

RequestDispatcher RequestDispatcher = Request.getrequestdispatcher ("/spr/txtrwt?url=" +url+ "&urlNoHost=" +url_ NOHOST2);

Requestdispatcher.forward (request, response);

4. excluding oneself (apache_mode_rewrite)

Rewritecond%{request_uri}!=/process.php

Rewritecond%{request_uri}!^.* (\.JS|\.GIF|\.PNG|\.JPG|\.JPEG|\.XML|\.ICO|\.CSS)

#other pic css JS Proxy

Rewritecond%{request_uri}!=/process.php

Rewritecond%{request_uri}!=/lensyaohwer/basic.png

Rewriterule ^ (. *) $ http://lengxiaohua.com/$1 [p,l]

2. Java implementation excludes itself

Except

if (Requesturi.contains ("SPR/TXTRWT"))

{

Chain.dofilter (request, response);

Return

5. Content Rewriting (PHP mode_rwt)

A. Text regular expression style

$content =preg_replace ('/Miss Si/', ' hammy ', $content);

$content =str_replace (' http://img.spriteapp.cn/ws/www/img/layout/logo.png ', ' http://img.spriteapp.cn/ws/www/img/ Layout/logoxx.png ', $content);

$content =str_replace (' No sis ', ' hammy ', $content);

B.html Dom Way

NbP

Require_once "simple_html_dom.php";

$html = str_get_html ($content);

$arr = $html->find (' web_content_right. Web_right_down ', 0);

$arr->innertext= ' A2 ';

Echo $html;

3. Java content rewriting

@RequestMapping (value = "/TXTRWT", produces = "text/plain;charset=gb2312")

@ResponseBody

Public Object process (HttpServletRequest request,

HttpServletResponse response) throws Exception {

Core.log ("=========process.json");

String URL = "" + request.getparameter ("url");//+ "?" +request.getquerystring ();

String url_no_host=request.getparameter ("Urlnohost");

System.out.println (); Request.getparameter ("Tid")

System.out.println (Request.getquerystring ());

if (Url.endswith ("jpg") | | url.endswith ("JPEG") | | url.endswith ("GIF")) {

if (Url_no_host.startswith ("/http://"))

{

String Url3=url_no_host.replaceall ("/http://", "http://");

byte[] ba = Websitex. Webpagecontent_bin (URL3);

if (!isljjpg (BA))

Outputimg (response, URL);

}

Else

Outputimg (response, URL);

}

//

Else

Outputtxt (response, url,request);

return null;

6. Content Rewriting---Absolute path link rewrite 4. Abs URL 2/app/http://xxxxxx.jpg

private void Outputtxt (httpservletresponse response, String URL, httpservletrequest request)

Throws Unsupportedencodingexception, IOException {

map<string, string> headprops = Mapx

. <string, String> $ ()

. Add ("Cookie",

"Lastfid=0; LASTVISIT=9271%091408838229%09%2FREAD.PHP%3FTID%3D1715718%26FPAGE%3D2; ol_offset=32204; ipstate=1408836660; __utma=99888095.1396678057.1405101634.1408806230.1408837132.29; __utmz=99888095.1405101634.1.1.utmcsr= (direct) |utmccn= (direct) |utmcmd= (none); __utmc=99888095; Pin6=done; __utmb=99888095.3.10.1408837132 ")

. Tomap ();

String Txt=websitex. webpagecontento8f (URL, "GBK", headprops);

Txt=txt.replaceall ("http://", pathx.webapppath_webfmt (Request) + "/http://");

5. Filter two times navigation

if (Url_nohost.startswith ("/http://"))

{

String url5=url_nohost.substring (1, Url_nohost.length ());

String url5_encode= Urlencoder.encode (URL5);

RequestDispatcher RequestDispatcher = Request.getrequestdispatcher ("/spr/imgrwt_abspath?url=" +url5_encode+ "& Urlnohost= "+url_nohost2);

Requestdispatcher.forward (request, response);

Return

} 6. To judge and instead of rewriting

@RequestMapping (value = "/imgrwt_abspath")

@ResponseBody

Public Object Process_imgrwt_abspath (HttpServletRequest request,

HttpServletResponse response) {

Core.log ("=========process.json");

String URL = "" + request.getparameter ("url");//+ "?" +request.getquerystring ();

String url_no_host = Request.getparameter ("Urlnohost");

System.out.println (); Request.getparameter ("Tid")

System.out.println (Request.getquerystring ());

byte[] ba = Websitex. Webpagecontent_bin (URL);

if (!isljjpg (BA))

Outputimg (response, URL);

if (isljjpg (BA))

Outputimg_garfile_holder (response);

return null;

}

/**

@author attilax old wow claws.

\t@since Aug, 2014 8:48:02 pm$

* @param response

*/

private void Outputimg_garfile_holder (HttpServletResponse response) {

Attilax old wow Claws 8:48:02 PM Aug 23, 2014

{

String URL = pathx.classpath () + "/com/attilax/clr/def.jpg";

byte[] ba = filex.readimagedata (URL);

Outputimg (response, URL, BA);

}

} 7. Reference

Paip. Reverse proxy and content rewriting based on Urlrewrite

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.