+ Post New Thread
Results 1 to 7 of 7
Internet Related/Filtering/Firewall Thread, Apache rewrite in Technical; Can anyone explain to me how to use Mod Rewrite in Apache 2 to do the following? I want to ...
  1. #1

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,941
    Thank Post
    519
    Thanked 2,498 Times in 1,939 Posts
    Blog Entries
    24
    Rep Power
    840

    Apache rewrite

    Can anyone explain to me how to use Mod Rewrite in Apache 2 to do the following?

    I want to rewrite any mention of 'servername' with 'differentservername'.

    So basically, if the site has an absolute link http://servername/blah.jpg it should instead return http://differentservername/blah.jpg

  2. #2

    Join Date
    Oct 2007
    Location
    Northamptonshire
    Posts
    312
    Thank Post
    21
    Thanked 82 Times in 69 Posts
    Rep Power
    45
    You could use a redirect. I had to do a similar thing for our Apache server when we changed our domain name and it works how you describe.

    Code:
    <VirtualHost *>
    	ServerName servername
    	Redirect permanent / http://differentservername/
    </VirtualHost>

  3. #3

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,941
    Thank Post
    519
    Thanked 2,498 Times in 1,939 Posts
    Blog Entries
    24
    Rep Power
    840
    That isn't any use to us - it is reverse proxied so the server is not internet facing.

    I'm looking at ProxyHTMLURLMap at the moment, using mod_proxy_html.

  4. #4

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,941
    Thank Post
    519
    Thanked 2,498 Times in 1,939 Posts
    Blog Entries
    24
    Rep Power
    840
    I'll explain my issue further - on this site, rather than use relative urls in the CSS 'style' code, they've used full server domains - eg:

    Code:
    background-image:url(http://server/icons/spacer.gif)


    Rather than the more elegant way of doing it:

    Code:
    background-image:url(/sysicons/spacer.gif?bg=1)
    So, the way I was thinking I should do it would be:

    Code:
    ProxyPass / http://server/
            <Location />
                    ProxyPassReverse http://server/
                    SetOutputFilter proxy-html
                    ProxyHTMLURLMap http://server/ /
            </Location>
    But it doesn't seem to be rewriting...

  5. #5


    Join Date
    Feb 2007
    Location
    51.403651, -0.515458
    Posts
    9,127
    Thank Post
    232
    Thanked 2,734 Times in 2,015 Posts
    Rep Power
    799
    Would this work?

    Code:
    Redirect 301 http://servername/blah.jpg http://differentservername/blah.jpg

  6. #6

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,941
    Thank Post
    519
    Thanked 2,498 Times in 1,939 Posts
    Blog Entries
    24
    Rep Power
    840
    Quote Originally Posted by Arthur View Post
    Would this work?

    Code:
    Redirect 301 http://servername/blah.jpg http://differentservername/blah.jpg
    No. That wouldn't rewrite anything - it'd just redirect any requests to the server for http://servername to http://differentservername - but as I said, differentservername is not an internet facing server - it is being reverse proxied.

  7. #7

    localzuk's Avatar
    Join Date
    Dec 2006
    Location
    Minehead
    Posts
    17,941
    Thank Post
    519
    Thanked 2,498 Times in 1,939 Posts
    Blog Entries
    24
    Rep Power
    840
    I got it working by changing some other settings instead.

SHARE:
+ Post New Thread

Similar Threads

  1. [Hosting] Apache Rewrite Rule Tester
    By russdev in forum Web Development
    Replies: 0
    Last Post: 29th December 2010, 02:57 PM
  2. Apache rewrite
    By Michael_84 in forum Web Development
    Replies: 0
    Last Post: 1st December 2008, 12:57 PM
  3. Apache Question.
    By in forum Web Development
    Replies: 6
    Last Post: 27th April 2006, 09:29 AM
  4. Apache + IIS On the same box?
    By in forum Windows
    Replies: 25
    Last Post: 7th March 2006, 03:12 PM
  5. URL rewriting with Squid?
    By ChrisH in forum *nix
    Replies: 8
    Last Post: 14th November 2005, 10:35 AM

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •