Regex help for URL rewriting

I have the following regular expression for rewriting a URL (from existing code which I had to make some quick changes)
String     regex = "s#(href|src|url|action|background)=(\"?)(/|" + "http:originalserver.com" +"/|http.?://" + "originalserver.com"+ ")([^\">]*?)(\"?)#$1=$2" + "myserver.com" + "/$4$5#gis";
which does a URL rewrite and changes the URL from something like
src="http://originalserver.com/images/someimage.gif" to
src="http://myserver.com/proxy/images/someimage.gif"
Now I want to change this regex to add some parameters to the URL. ie.
case 1:
href="http://www.originalserver.com/index.htm"
to
href="http://www.originalserver.com/index.htm?myParam1=myValue1
case 2:
href="http://www.originalserver.com/index.htm?originalP1=originalV1"
to
href="http://www.originalserver.com/index.htm?originalP1=originalV1&myParam1=myValue1"
How can I change the regex to do this. As I have to do this fast and not an expert in Regex, any help would be appreciated.

Hi,
try this :
- first set delimiter (? or &) to append your parameters :
char delimiter = '\?';
String myParams = "myParam1=myValue1";
Pattern p = Pattern.compile( "\?" );
Matcher m = p.matcher( url );
if( m.matches() )
delimiter = '\&'; // not sure ampersand needs to be "backslashed"
- then use the modified regex
String regex = "s#(href|src|url|action|background)=(\"?)(/|" + "http:originalserver.com" +"/|http.?://" + "originalserver.com"+ ")([^\">]*?)(\"?)#$1=$2" + "myserver.com" + "/$4$5" + delimiter + myParams + "#gis";

Similar Messages

  • Need help for URL

    I got my domain from godaddy.com. and for example my domain name is www.needhelp.com
    when i do publishing on .mac, it changes the url to www.needhelp.com/site/blog OR something like that.
    I want it so that when people type www.needhelp.com on their browers, the homepage will make the brower stay at www.needhelp.com instead of adding all these other extensions or whatever
    someone please help

    so youre saying that i cant edit my website with iWeb?
    Not at all. Doing Domain Forwarding/Masking at Godaddy has no connection with how you edit and publish your site.
    But if you have already gone through he process of making a www CNAME entry at Godaddy, and setting your .Mac Account Settings for a personal domain, as required by the .Mac personal domain feature, you need to undo all that.

  • Regex help for SQL update statement

    Hello,
    need help from IPS regex guru - trying to build the signature to detect SQL update statement in HTTP requests.
    1) Am I correct with regex below specified as Request-Regex?
    [Uu][Pp][Dd][Aa][Tt][Ee]([%]20|[+])[\x20-\x7e]+[Ss][Ee][Tt]([%]20|[+])[\x20-\x7e]+=
    2) How do I make sure that it detects 'Update' in URI and Arguments only and not in the body on entire webserver response (currently looks like the case)?

    1) It looks correct to me
    2) Typically, the "service HTTP" engine is used to inspect requests and the "TCP string" engine is used to inspect HTTP server responses. If you only want to inspect requests, use the service HTTP engine.

  • URL rewriting issue

    Hello all,
    I am having a url rewriting issue where the first time someone accesses the website with a browser that has cookies enabled my jsp pages will still encode all of the URL's with the jsessionid. Which I believe should not happen unless cookies are disabled.
    Why is this occuring?
    Once the user goes to another page in the site or the second time they bring up the site in the same browser the jsessionid is not written to the URL links. This only happens on first access.
    I am using Tomcat 5.5
    response.encodeURL() to encode the links
    Is this a container or programming error?
    Thank you all very much for your time in reading this!

    Ok, thank you.
    Based on this: http://www.sciabarra.com/fatwire/2011/04/17/improving-the-firstsiteii-url-assembler/
    I think my approach would work if I remove the Asset API stuff from here and put them into a helper class, which would be then called from the wrapper JSP.
    I'd rather not install 3rd-party extensions just for url rewriting, at least not yet...

  • URL Rewriting & Mozilla

    I've noticed some functional changes between SJSAS 8 Update 1 and SJSAS 8 2004Q4 Beta regarding use of URL rewriting in webapps.
    Our servlet explicitly disables cookies in preference for URL rewriting. In SJSAS8-Update1, as for every other app server we've used (SJSAS 7 2004Q2, S17AS, Weblogic 8, Jboss), this works fine. But in the 2004Q4 beta release, URL rewriting doesn't work in Mozilla. IE works as per usual - inserting the relevant jsessionid's in the address bar.
    Consequently when the browser attempts to hit the servlet for the second time - it has no jsessionid, and the servlet doesn't recognize the session.
    As I said, this isn't a problem with any other release of the product; it seems to have been introduced in this most recent 2004Q4 beta of S1JSAS 8.
    Anyone else noticed this or have any suggestions?

    More specifically, the problem appears to exist -only- in Firefox (not Mozilla in general).
    Using LiveHTTPHeaders, its clear that Firefox 1.0 is setting the jsessionid identifier as a cookie, as opposed to URL rewriting. The other parameters are correctly passed using URL rewriting.
    Thus Mozilla is sending a URL without the jsessionid and the appserv web container cannot locate the session.
    We've set our sun-web.xml file to disable cookies explicitly using "enableCookies=false". However, Sun Appserv 8.1 2004Q4 BETA sends back a cookie to Firefox's request - even though the webapp has disabled it...
    Very frustrating!! Any help/suggestions would be gladly appreciated!

  • Does URL rewriting in JBuilder4 work?

    I am writing a shopping cart application.
    To keep track of the products the user has chosen I am using a URL rewriting code that appends the product details to the URL and then requests the same page again.
    <a href="<%= response.encodeURL(shopproducts.jsp?title="+title+"&item_id="+item_id+"&price="+price) %">">
    In this page there is a response that will add the chosen product to the shopping cart using a piece of JSP code.
    <% String title = request.getParameter("title");
    In JBuilder4 when I click on the request code I get an error.
    Unable to open location: Could not connect to: http://localhost:8080/myproject/easyshop/shopproducts.jsp;jsessionid=To1010mC02444678198891448At?title=Java 2&item_id=1&price=10
    Is this because JBuilder dosent know how to keep track of the session ID?
    If so how can I get round this or if not is there a better way to keep track of the items?
    thanks.</a>

    Take a look at UrlRewriteFilter for URL Rewriting.
    This particular URL http://localhost:8080/myproject/easyshop/shopproducts.jsp;jsessionid=To1010mC02444678198891448At?title=Java 2&item_id=1&price=10
    has ;jsessionid=.............. after shoppingproducts.jsp
    But a valid URL looks something like this
    somepage.jsp?someValue=123&anotherValue=456
    So having that semicolon instead of a question mark immediately after the .jsp , might be what's causing the error.
    If you have doubts , try to access the page by putting the entire URL
    http://localhost:8080/myproject/easyshop/shopproducts.jsp;jsessionid=To1010mC02444678198891448At?title=Java 2&item_id=1&price=10
    into your browser.
    If your browser can't connect then, what ever you are using to connect to that URL can't connect either.
    Then remove the semicolon and jessionid part, and try to connect and see if it works.

  • Using Tomcat URL rewrite valve

    http://tomcat.apache.org/tomcat-8.0-doc/rewrite.html
    Looks like the latest version of Tomcat has added support for URL rewriting similar to Apache mod_rewrite
    I can't seem to find any documentation other than the page above.
    Has anyone used this to, for example, rewrite APEX URLs from http://host:port/apex/... to http://host:port/pls/apex ?  Where should we put the RewriteCond and RewriteRule directives?
    Thanks

    I just went though this, spent about two days trying to figure out how to do with only tomcat and gave up.  I found and used urlrewrite..  The instructions are right on main page but are vague.  I've given "hints" below.  My info assumes you renamed ords.war to apex.war.   I tried to post full details of my exploits/trials/troubles using the Oracle blog but it errored out.
    http://tuckey.org/urlrewrite/
    Step 1 say to place the file in WEB-INF/lib.  For Tomcat, WEB-INF is the Tomcat application directory, mine was /opt/apache-tomcat-7.0.56.   Place in the <tomcat_app_dir>/lib directory.
    Step 2 says to edit the web.xml file, adding the config text for urlrewrite.  This file is located in <tomcat_app_dir>/ROOT/WEB-INF  Copy text and paste just above the </web-app> tag at the bottom of the <tomcat_app_dir>/ROOT/WEB-INF/web.xml file.
    Step 3 talks about editing urlrewite.xml file, which doesn't exist.  You must create this file, in the same directory, <tomcat_app_dir>/ROOT/WEB-INF. The following is the contents of mine.
    <urlrewrite use-query-string="true">
                    <note>
                     rewrite from /pls/apex to pls
                    </note>
           <rule>
                <from>/pls/apex/f\?p(.*)</from>
                <to type="redirect">/apex/f?p$1</to>
            </rule>
    </urlrewrite>
    You can check that urlrewite is working by accessing the admin/test page from the localhost....<servername>:8080/rewrite-status.  The page shows you the rule and what it thinks it's going to do.
    You now need to restart Tomcat and your old URL <servername>/pls/apex should work for your users who have bookmarked your old apex apps.  It works for the new URL as well:  <servername>/apex
    I noticed you are also referencing port numbers in your sample url.  Take a look at this blog post below, specifically step 6 and 7 to learn how to redirect to 80, so you don't have to use a port.
    Install Tomcat 7 on CentOS, RHEL, or Fedora : David Ghedini

  • Webcenter URL Rewrite solution?

    Hello,
    There is some in-box solution for URL Rewrite in webcenter portal?
    Anyway, what to use as workaround? Apache?
    thank you.

    Did u ever tried to visit blog-
    GEORGE MAGGESSY: WebCenter Portal Pretty URL Beyond Limits
    you will find it useful.
    --Hoque

  • Always use URL Rewriting for session tracking?

    All you JSP guru:
    I am working on a JSP project that requires session tracking. I have successfully implements session tracking with both cookies or URL rewriting. I know that with the HttpSession object, it will always try to use cookie first, if that's disabled, then it'll automatically switch to URL rewriting. However, is there a way to force the HttpSession object to ALWAYS use URL rewriting instead of cookies? I have searched for an answer for a long time and haven't been able to found a solution. Is it possible at all? Thank you very much.

    i was going to say that WebSphere always uses URL rewriting if you enable it at all, but someone beat me to it (indirectly) :-)
    however, that seemed to me to be a violation of the spec, which seemed to imply the behaviour you're describing (only use URL rewriting if cookies are not supported on the current client)
    here's a response someone else made on a websphere newsgroup to a statement in that regard:
    I believe you are technically correct. However from my
    experience, I think the spec if flawed in this area since
    there is no reliable way of determining whether the
    client browser supports cookies. The authority on
    cookies (www.cookiecentral.com) says:
    "To properly detect if a cookie is being accepted via
    the server, the cookie needs to be set on one HTTP
    request and read back in another. This cannot be
    accomplished within 1 request."
    This is asking too much of a servlet engine
    implementation. Even if it did submit a request for this
    purpose, the user could refuse the cookie. So
    then technically the browser supports cookies, but the
    servlet engine infers it doesn't. So if the servlet engine
    infers the browser does not support cookies and so
    encodes the URL, it is again out of spec because the
    browser really does support cookies. By doing it
    however encoding is configured makes things simpler,
    robust, consistent and avoids the flaw.
    My opinion.so, mostly i'm just rambling, but if you're using websphere, you should get the behaviour your boss wants. if you're using something else, i suppose there's a chance it'll "violate" the spec in this same, potentially helpful way.
    btw, i remember somebody else complaining that URL rewriting is less secure than cookies, but i kinda think they're about equal. it seems like either could be intercepted by a sniffer and then used to spoof. but i'm no expert in that stuff...

  • Supress URL rewriting through gateway for specific URL's ??

    I want to know how to supress URL rewriting for some spcific URL's. Currently the property "Rewrite All URL's" is set to true in the gateway profile.
    Default ruleset is applied on to the rewriter during installation. Do I need to write a ruleset to achieve this ?? If yes, how to approach onto developing this ruleset.
    Please help.
    Thanks.

    I don't think what you ask is possible, but the reverse is.
    Do not select Rewrite All URL's. In my knowledge it really is all and no exceptions possible. BTW The ruleset define what's inside HMTL etc., not which links are to be rewritten.
    Solution:
    In Admin console:
    Service Management -> Gateway-> <your gateway profile> ->Proxies for Domains and Subdomains
    Fill this with the domains you want rewritten. All other domains are not rewritten.
    Lemme know if this helps.
    This site (and the Sun One Portal) needs feedback!
    Ronald

  • URL rewriting for a WebService Consumer Proxy

    Hi all,
    Did anybody come across this issue?
    I have a SAP System - let's call it "TM" -  that I want to bind with another non-SAP one - let's call it "FB" - without any PI between them.
    The communication is made as a Service Consumer (TM side), the Proxy (see image below) and Proxy-Implementation Class being generated automatically after the ".wsdl" file and the "url" given by the documentation of FB.
    Everything looks good! All the Methods (operations) that are available from the service have been added to the Implementing Class.
    After the Proxy generation, I also created the Logical Port (in transaction SOAMANAGER - see image below) where the path, host, prefix, and all the necessary stuff were also automatically created after the ".wsdl" document.
    So far so good! When I want to test it and to play along with this connection TM -> FB, I am creating the Proxy-Object, I am filling the required User / Pass / and an ID in order to call the first method. As you have probably guessed already: LOGIN.
        ls_in_login-login_request-id             = '...some ID...'.
        ls_in_login-login_request-user          = '...some user ...'.
        ls_in_login-login_request-password  = '...some password'.
    TRY.
             CREATE OBJECT lo_proxy
               EXPORTING
                 logical_port_name = 'ZAS_PORT_FB'.
         CATCH cx_ai_system_fault INTO lo_ref.    " Application Integration: Technischer Fehler
    ENDTRY.
       TRY.
           CALL METHOD lo_proxy->login
             EXPORTING
               input  = ls_in_login
             IMPORTING
               output = ls_out_login.
         CATCH cx_ai_system_fault INTO lo_ref.    " Application Integration: Technischer Fehler
         CATCH cx_ai_application_fault INTO lo_ref.    " Application Integration: Applikations Fehle
    ENDTRY.
    As a response, (meaning that the connection works and that the WebService acknowledges the connection) I get a "SessionID" -> a string of characters.
    In the Wiki of the Service is written that from this point on, every other methods (but I mean ALL of them, logout() also...) need to be called along with this SessionID. The problem is, that this SessionID doesn't have a specific place in the "inbound"-structure of the methods, but this mechanism of passing around the SessionID must be made with URL rewriting. Another solution would be to use COOKIES. From my point of view, a so-called URL rewriting would be easier, right?
    In the documentation is the following info written:
    URL rewriting (recommended):
    The JSessionId is attached to the URL of the SOAP request, as follows:  http://[URL];jsessionid=[jsessionid]
    Caused by tecnical reasons, it is necessary to specify the static string “;jsessionid=” in lower case letters.
    I have turned this "LO_PROXY" object around and around and around... trying to find a solution... a method...anything that would let me rewrite the URL, but nothing...
    I have also tried to use ce CL_HTTP_CLIENT class and to create myself the client and the URL and the host and everything manually... but in this case how do I end up in calling a specific "custom" method -> for instance... how do I call the "LOGIN"... or the LOGOUT...where do I put the parameters, etc?
    Do you have any suggestions / ideas / hints ?
    Thanks a lot in advance!
    Warm regards,
    Alex

    Hi Stefan,
    You are right! It doesn't support to set URL / HTTP parameters outside the logical port.
    Nevertheless, I have debugged the whole engine and found out that via custom coding (enhancements / modifications) and with extreme attention, the URL can be rewritten as desired.
    When a method of the proxy is called, let's say for instance: lo_proxy->logout (...) - as written up for example, the method CL_HTTP_CLIENT=>CREATE_BY_URL is called dynamically.
    In this method, in the "url" variable is the desired URL that needed to be rewritten.
    Here it's about an importing parameter, so it cannot be changed so easily, but it's not impossible.
    Another place where a nice Enhancement can be created is at the beginning of the FM "SWLWP_URI_PARSE".
    You need to be very careful not to change these places in all cases (this CREATE_BY_URL will be called pretty much), JUST when the specific conditions are fulfilled.
    Have a great day / week!
    Warm regards,
    Alex

  • Regex for url pattern validation

    Hi,
    I am trying to find a regex for Url pattern validation that is not too restrictive.
    Please let me know, if anyone is using a pattern for their applications.
    Thanks
    Mayank Sharma

    are you talking about xml schema restriction?
    <xs:element name="url">
      <xs:simpleType>
       <xs:restriction base="xs:string">
        <xs:pattern value="(https?://)?[-\w.]+(:\d{2,5})?(/([\w/_.]*)?)?" />
       </xs:restriction>
      </xs:simpleType>
    </xs:element>

  • APEX: Internet domain mapping / URL rewrite for Apps in the cloud

    Hello,
    I have registered for a trial access since first day in which the cloud was launched ... But, did not get access till now ... If I were to buy it, am I going to get access right away ??
    Is Oracle Cloud going to offer Internet domain name mapping to a specific APEX application ???
    Is Oracle Cloud u going to offer URL rewrite where APEX URL is not Search Engine friendly.... e.g:
    This site: http://www.enkitec.com/ was built on APEX, but as you can see the URL was rewritten ????
    Best Regards,
    Fateh

    Hi,
    According to your post, my understanding is that the rule was not processing for SharePoint 2013 result page.
    Please make sure you add the reverse rewriting rule correctly.
    For more information, you can refer to:
    Add the reverse rewriting rules (in the HTML)
    Setting up a Reverse Proxy using IIS, URL Rewrite and ARR
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

  • Apache Url rewrite for portal URLs

    Hi,
    I have a requirement where i need to write simple URL's for the default portal uRL's
    for example
    inspite of using default url like "http://myserver:port/portal/server.pt/community/abc_xyz/123/efg_jkl/12345",
    if user uses
    "http://myserver:port/portal/server.pt/xyz"
    It should navigate to same default URL.
    Can somebody let me know how this can be achieved.
    I know Url rewriting is done through Apache Url rewrites but do not have an idea how apache does it with portal Url's. What configurations need to be done in order to manage portal Url's with apache rewrites.
    Thanks
    Ajay

    Hi Ryan,
    Thanks for the reply. The link shows how to write the Rewrite rules in apache. I am familier with that. The actual problem is that how can the portal Url's be controlled by apache rewrites. My apache and weblogic are both on the same server instance but after writing the rewrite in httpd.conf file. It does not work out. Just want to know how can i tell apache to handle my portal Url's too.
    Is there any specific entry that we need to make for doing this.
    Thanks
    Ajay

  • URL rewrite now working for SharePoint 2013 result page

    Hi,
    I have configured reverse proxy using URL Rewrite (ARR), all works fine but the rule is not processing for SharePoint 2013 result page. It still shows internal domain name and not external domain name.
    this is my web.config in internet web server
    <?xml version="1.0" encoding="UTF-8"?>
    <configuration>
        <system.webServer>
            <rewrite>
                <outboundRules>
                    <rule name="ReverseProxyOutboundRule1" preCondition="ResponseIsHtml1">
                        <match filterByTags="A, Area, Base, Form, Frame, Head, IFrame, Img, Input, Link, Script" pattern="^http(s)?://dsplsp2013/(.*)" />
                        <action type="Rewrite" value="http{R:1}://uncep/{R:2}" />
                    </rule>
                    <preConditions>
                        <preCondition name="ResponseIsHtml1">
                            <add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
                        </preCondition>
                    </preConditions>
                </outboundRules>
                <rules>
                    <rule name="ReverseProxyInboundRule1" stopProcessing="true">
                        <match url="(.*)" />
                        <action type="Rewrite" url="http://dsplsp2013/{R:1}" />
                        <serverVariables>
                            <set name="HTTP_ACCEPT_ENCODING" value="" />
                        </serverVariables>
                    </rule>
                </rules>
            </rewrite>
            <urlCompression doStaticCompression="false" />
        </system.webServer>
    </configuration>
    Thanks
    Hari
    Hari

    Hi,
    According to your post, my understanding is that the rule was not processing for SharePoint 2013 result page.
    Please make sure you add the reverse rewriting rule correctly.
    For more information, you can refer to:
    Add the reverse rewriting rules (in the HTML)
    Setting up a Reverse Proxy using IIS, URL Rewrite and ARR
    Best Regards,
    Linda Li
    Linda Li
    TechNet Community Support

Maybe you are looking for

  • HT1435 ipod not charging and windows says usb device malfunctioned. Any Ideas?

    alright so i have the ipod connected to my windows laptop however, ipod asks to be plugged into a power supply. windows says "the usb device plugged in has malfuctioned, and windows does not recognize it" Has anyone ever encountered anything similar

  • Can't update to iOS 4.2.1. Please help

    Hello everyone, I have got a Second Generation iPod touch, which is running on iOS 4.0.2, and I thought it should be updated. Now I've downloaded iOS 4.2.1 directly from iTunes, this is the last firmware the 2G iPod touch can handle, but anytime I wa

  • Problem in Uploading sales order text data using LSMW

    Hi All, I am facing Problem in uploading open sales order data from legacy to SAP using LSMW. We are trying to upload sales order data using LSMW Standard Batch/Direct input using program name RVINVB10 and program type D. We are not able to upload it

  • Z-index problem in IE and Firefox

    Hello I have created a site with templates and absolute position divs that are nested inside a wrapper div.  For a menu I am using the spry horizontal widget. The menu is a non editable item in the template. There are some editable regions besides th

  • How to make Recovery Partition in my new HDD (Win8.1)

    I already re-install my Win8 with usb. But after finish the installation (I choose Fully Clean in my new HDD), why there is no Recovery Partition like my old HDD (original HDD)? how to make a Recovery Partition in my new HDD? Thx