Forum Moderators: phranque

Message Too Old, No Replies

Converting static URLs

between test and live servers

         

steve

2:16 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



I've built a local server on an old pc using linux and Apache2, which is set up to serve name based virtual hosts. The server is on my local network, and is not visible to the outside world.

Rather than editing the host files on the other network pc's, I've installed bind9 to handle local dns, and to act as a caching internet dns for all the other pc's.

At the moment for each live site, hosted elsewhere, I have a local development site named 'local-domainname.tld'.

This means if I want to use absolute URL's I have to manually rewrite the links as follows:
www.local-domain.tld/folder/file --> www.domain.tld/folder/file

Is there a way to configure my local server to accept URL's without the 'local-' part but still link to the local page?

ChadSEO

4:46 pm on Mar 3, 2006 (gmt 0)

10+ Year Member



Steve,

I can think of two ways you may be able to do this:

1) mod_proxy:
I've never used mod_proxy, so I have no idea if this will actually work, but I think you could do something like this:
ProxyRequests On
ProxyRemote http://domain.tld http://local-domain.tld
You would then have to configure your browser's proxy settings to point to that server. If you didn't want everyone on your network affected, this would work well.

2) Assuming your network is using one of the private IP blocks - 192.168.x.x or 10.x.x.x - then you could set the DNS for each site to a unique IP address, and configure Apache for IP-based virtual hosting. It would then respond whether the domain was domain.tld or local-domain.tld. You also have to configure linux to listen to each of those IP addresses, but this isn't too difficult in the grand scheme of things. This would effect everyone on your network, assuming they use the same DNS servers.

Let me know if I stopped making sense at any point, I tend to do that :) Good luck!

Chad

steve

2:22 pm on Mar 4, 2006 (gmt 0)

10+ Year Member



Thank you for the suggestions Chad, neither really solve my problem :-(

At the moment for each website I have two versions!

On my development server "local-mywebsite.tld" which is only visible to pc's on my local network, and a corresponding "mywebsite.tld" with my hosting company.

I'm trying to get rid of the "local-" bit of the URL's so I can have just have one copy of each site.

So far I've found two possible solutions:

1) Use relative addressing i.e /.../.../filename addressing everything relative to the root. I not keen on this.

2) Put the 'local-mywebsite' or 'mywebsite' bit of the URL's into a php variable and set it accordingly.

This must be a common problem, I'm wondering how other people have worked round it?

jdMorgan

4:21 pm on Mar 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It's typical to use a hostname variable for scripts and mod-rewrites in this situation, to make your code 'portable' from host to host. Just for an example, to redirect an obsolete URL in .htaccess:

RewriteRule ^old_URL$ http://%{HTTP_HOST}/new_URL [R=301,L]

Jim

[edit] De-linked [/edit]

[edited by: jdMorgan at 4:33 pm (utc) on Mar. 6, 2006]

steve

9:49 am on Mar 5, 2006 (gmt 0)

10+ Year Member



Thanks Jim. I've had a brief look at mod_rewrite, it looks like it will do the job. So I've got some reading to do in the next few days!

As someone used to windows servers and IIS it's amazing the power and flexibility available with Apache. Not to mention the price, I have built a complete 'production spec' web server to play with, and haven't spent a penny on software or licencing.

I've only been experimenting with linux and Apache since January, but I can already see that I'll be leaving my Windows/IIS hosting company very soon!