Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8870247
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:40:36+00:00 2026-06-14T17:40:36+00:00

I have http proxy project. There’re some rewrite rules I use to change all

  • 0

I have http proxy project. There’re some rewrite rules I use to change all actions and href’s to this /follow/+URL. I also change all src’s URLs to this /proxy/+URL, it helps me to assign the URLs between the links and e.g. images. It works fine with <img> tag though. The problem I have consists in <iframe src=...> tag. After I apply my code it changes src to ‘/proxy/+URL’ but I want to change it to /follow/+URL and I’m not sure how I can do that.

Here’s my code

from urlparse import urlparse, urlunparse
import re, urllib


REWRITE_LINKS = re.compile(r'((?P<attr>action|href|src)=["\'](?P<uri>\S+?)["\'])', re.IGNORECASE)


def rewrite_links(content, mimetype = '', uri = ''):
    uri = str(uri)
    urip = urlparse(uri)
    server_root = str(urlunparse((urip[0], urip[1], '/', '', '', '')))

    working_dir = str(urlunparse((urip[0], urip[1], urip[2], '/', '', '')))
    working_dir = '/'.join(working_dir.split('/')[:-1])

    def repl_html(match):
        attr, value = match.groupdict()['attr'], match.groupdict()['uri']

        if value in ('',) or value.startswith('javascript:') or value.startswith('#'):
            pass
        else:
            if value.find('://') == -1:
                if value.startswith('./'):
                    value = working_dir + value[2:]
                elif value.startswith('../'):
                    value = '/'.join(working_dir.split('/')[:-1]) + value[3:]
                elif value.startswith('/'):
                    value = server_root + value[1:]
                else:
                    value = server_root + value
            #value = value.replace('/','|')
            if attr.lower() == 'src':
                value = '/proxy/' + value
            else:
                value = '/follow/' + value

        return ' %s="%s" ' % (attr, value)

    if mimetype.startswith('text/html'):
        content = REWRITE_LINKS.sub(repl_html, content)
    elif mimetype.startswith('text/css'):
        pass
    elif mimetype.startswith('application/x-javascript'):
        pass
    else:
        pass

    return content

Do you have any advices?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:40:38+00:00Added an answer on June 14, 2026 at 5:40 pm

    You could try adding an extra named group:

    <(?P<tagname>[^\s]+)\s[^>]*
    

    to the REWRITE_LINKS line like this:

    REWRITE_LINKS = re.compile(r'(<(?P<tagname>[^\s]+)\s[^>]*(?P<attr>action|href|src)=["\'](?P<uri>\S+?)["\'])', re.IGNORECASE)
    

    then you can query this match in the if attr.lower() == 'src': conditional statement

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a local HTTP proxy which I use to inject scripts into the
I have an dialog for HTTP proxy configuration with hostname and port edit boxes.
I have Ruby script that creates a proxy so that I can make HTTP
I have the following POST request: POST http://blah/Request HTTP/1.1 Host: blah Content-Length: 322 Proxy-Connection:
I have http compression turned on in my production IIS box. Is there a
I need to have : http://www.example.com/v1/my-project/ redirected to http://example.com/my-project/ so : (1) remove the
I built a project as descripted in this URL: http://msdn.microsoft.com/en-us/library/ms734784.aspx I used the app.config
I have used the signalR chat app (as laid out in this tutorial http://sergiotapia.com/2011/09/signalr-with-mvc3-chat-app-build-asynchronous-real-time-persistant-connection-websites/
I have a haproxy configuration like this: frontend api mode http default_backend tomcat backend
I have some problem in my project. I want to delete my file from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.