Redirect website but keep the original url in the address bar

Redirect website but keep the original url in the address bar

  1. Blog
  2. 15 November 2026
  3. 4 min read

Stefan Bogdanescu

Founder & Senior Architect

Redirect website but keep the original url in the address bar

You want to serve content from a .com domain while forcing the browser's address bar to display your controlled .dz domain. The core challenge is that standard HTTP redirects (301, 302) replace the URL in the address bar with the target of the redirect. To keep the original URL visible, you cannot use a server-side redirect header; you must intercept the request on the server controlling the .dz domain and serve the content dynamically.

Since you have confirmed that your .dz domain does not allow DNS changes, you are likely hosting the web server configuration for it. The solution depends entirely on which server software controls the .dz domain (e.g., Apache, Nginx, or a custom PHP environment). You cannot simply "read directly from the .com domain" using a PHP function like file_get_contents() if the .com server blocks cross-origin requests via CORS headers. Even if it doesn't block them, fetching an entire site via PHP is inefficient and defeats the purpose of proper caching.

The most robust approach involves modifying the virtual host configuration for the .dz domain to serve a custom response that includes the correct HTTP headers but with your own HTML content. If you are using Apache with access to .htaccess, you can attempt to rewrite the request internally, but you must be careful not to send a Location header.

Serving Content via PHP Proxy

If you prefer handling this logic in PHP files (as suggested in your inquiry), you can create an entry point script that fetches content from the external source and echoes it back. This is often called a "server-side proxy."

Here is a conceptual example of how such a file might look, assuming the .com server allows direct fetching:

<?php
// config.php for .dz domain

$target_url = 'https://www.yourcompany.com';

// Fetch content from the target domain
$response = @file_get_contents($target_url);

if ($response === false) {
    // Handle connection errors gracefully
    http_response_code(502);
    echo 'Service Unavailable: Could not reach upstream server.';
} else {
    // Echo the content back to the browser
    echo $response;
}
?>

Critical Implementation Details:

  1. CORS Headers: Before this code works, you must ensure the .com server sends Access-Control-Allow-Origin: * (or your specific domain) in its headers. If the .com server blocks cross-origin requests, PHP's file_get_contents() will fail or return an empty string due to security restrictions. You cannot bypass this without modifying the .com server configuration, which you likely do not have access to.
  2. Performance: Every time a user visits the .dz site, your PHP script makes an external HTTP request. This adds latency and relies on the availability of the remote server. If the .com server goes down, your .dz site displays a broken state or a generic error message.
  3. SEO and Tracking: While this method keeps the URL in the address bar, search engines might treat the content as dynamically generated. Additionally, you lose access to real-time analytics on the remote page unless you parse the response yourself.

Using Apache Rewrite Rules

If you have access to .htaccess, a more standard approach is to use an internal rewrite that serves a PHP handler instead of redirecting externally. However, this requires careful handling of headers.

You must ensure no Location header is sent. Instead, you configure the server to return a 200 OK status with the content fetched from the remote source. Note that standard .htaccess directives often cannot fetch external URLs directly; they usually require an internal handler (like PHP) to do the fetching.

An alternative is to use mod_remoteip or similar modules if you specifically need header manipulation, but for content serving, the PHP proxy method described above is the only one that guarantees the URL in the address bar remains unchanged while hiding the actual source domain completely.

Trade-offs and Limitations

The primary limitation of this architecture is the dependency on the remote server's CORS policy. If the .com owner does not configure their server to allow requests from your .dz domain, you cannot achieve this redirect-and-hide behavior without modifying their server code or DNS settings.

Furthermore, maintaining a PHP-based proxy introduces security considerations. You are essentially acting as an intermediary; if the remote server injects malicious scripts into its responses (XSS), they will be rendered in your users' browsers. You should sanitize output or use strict Content Security Policy headers on your side if you serve this content to public users.

For high-performance sites, consider using a reverse proxy setup (like Nginx) with proxy_pass directives pointing to the .com origin, provided the Nginx instance is located where you control the DNS and server blocks. This allows you to hide the origin IP but still requires careful header management to prevent the browser from seeing the real location if a redirect occurs at the edge.

Our network