Skip to content

Website & Server Help

Unlimited Webspace Help

Menu
  • Home
  • Apps
  • Website
    • Sending email from a WordPress website hosted on an IONOS server
    • How to increase Upload Max Filesize
    • How to reset a WordPress password
    • 22 Ways To Speed-Up A Plesk Website
  • Server
    • Linux or Plesk Server Error 500
    • Windows Server: File cannot be loaded. The file is not digitally signed.
    • Adding or modifying IP addresses on a Linux server
    • Installing Remote Desktop on Debian 12
    • Installing Remote Desktop on Ubuntu 22.04
    • How To Install a Let’s Encrypt SSL in Apache on Debian/Ubuntu
  • Favs
    • How to Connect to a Server
    • The Ultimate Guide to Setting Up a Proper Plesk Email Server With IONOS
    • The Ultimate IONOS Migration Guide
    • Help! My Plesk Websites Are Down!
    • Running tests for a slow server or dropped packets
    • Checking File System and Hard Drive Health
Menu

How to redirect a website or domain

Posted on February 20, 2023October 12, 2023 by admin

When it comes to redirecting traffic from one website or domain to another, it’s important to decide on a few factors first.

Is this a permanent redirect or temporary?

If you only intend on directing traffic to the new URL temporarily, until it returns back or changes again, you may consider one of the following types of redirects:

302 Found (or Moved Temporarily): This is a temporary redirect that tells search engines and web browsers that the requested resource has been temporarily moved to a new URL. This is often used for short-term changes or testing, and the original URL is expected to be available again in the future.

307 Temporary Redirect: This is similar to the 302 status code but is more specific in its intended usage. This redirect status code is used to indicate that the requested resource has been temporarily moved to a new URL, and the client should continue using the original URL for future requests.

If this is a permanent redirect, you may consider one of these redirects instead:

301 Moved Permanently: This is a permanent redirect that tells search engines and web browsers that the requested resource has been permanently moved to a new URL. This is the most common type of redirect used when a website or page is permanently moved.

308 Permanent Redirect: This is similar to the 301 status code but is more specific in its intended usage. This redirect status code is used to indicate that the requested resource has been permanently moved to a new URL, and the client should update its bookmarks and links to use the new URL for future requests.

Lastly, if this a different type of redirect, you may be looking for:

303 See Other: This redirect status code is often used in response to a POST request. It tells the client to issue a GET request to a new URL, which is typically the result of a form submission.

Apache or nginx?

To create a redirect in Apache,

the easiest way is to add a .htaccess file to the root document folder of the domain, and add the following content:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^web.space$ [NC]
RewriteRule ^ https://new.web.space%{REQUEST_URI} [R=301,L]

In this configuration, we enable the RewriteEngine and define a RewriteCond directive that matches the HTTP_HOST header to the web.space domain using the regular expression ^unlimitedweb.space$. The NC flag specifies that the match should be case-insensitive.

The RewriteRule directive then matches any request URI using the regular expression ^, which matches the beginning of the URI. The REQUEST_URI variable contains the rest of the URI, which is then appended to the new URL https://new.web.space. This means that original folder and link structures will continue to work on the new domain. The R=301 flag specifies that a 301 redirect should be issued, and the L flag specifies that the redirect should be the last rule applied.

Note that in order to use an .htaccess file for rewriting URLs, you need to ensure that the AllowOverride directive is set to All in the Apache configuration file for the corresponding directory. If AllowOverride is set to None, the directives in the .htaccess file will be ignored.

Hint: LiteSpeed web server is compatible with Apache .htaccess files, so you can use the same syntax and directives as you would with Apache. The mod_rewrite module is also supported in LiteSpeed, so you can use regular expressions to match and redirect URLs as needed.

The create a redirect in nginx,

You can edit the nginx config file ( /etc/nginx/nginx.conf ), to add the following (in between server { } brackets):

if ($request_uri ~* "^/.*$") {
return 301 https://new.web.space$request_uri;
}

This is an Nginx configuration directive that matches any request URI that starts with a forward slash (/) and redirects it to a new URL using a regular expression.

Here is a breakdown of the configuration directive:

The if statement defines a condition that must be met for the directive to take effect. In this case, the condition is a regular expression match on the request_uri variable.

The ~* operator specifies that the regular expression match should be case-insensitive (~), and that it should match the entire request_uri string (*).

The regular expression ^/.$ matches any string that starts with a forward slash (^/) and is followed by zero or more characters (.), and ends with the end-of-line anchor ($).

The return directive specifies that the web server should issue a 301 Moved Permanently status code and redirect the request to a new URL. The new URL is constructed using the new.web.space domain and the original request_uri variable.

When someone tries to access https://web.space/my-article they will be redirected to https://new.web.space/my-article .

Special Offer

The internet's fastest, cheapest, unlimited bandwidth VPS

VPS
1core | 1GB RAM | 10GB NVMe
Unlimited Bandwidth | 1Gbps
$2/month - risk free