The Apache virtual host configuration files are found in different places, depending on the distribution of Linux. For example, on CentOS 7: /etc/httpd/conf.d/vhost.conf; on Ubuntu 16.04: /etc/apache2/sites-available/ For the sake of brevity, configuration file excerpts in this guide will direct you to Apache configuration option.

Remember to reload Apache configuration after making changes:

CentOS 7

1sudo systemctl restart httpd</pre

Ubuntu 16.04

1sudo systemctl restart apache2

The Redirect Directive

Redirect settings can be located in your main Apache configuration file, but we recommend you keep them in your virtual host files or directory blocks. You can also use Redirect statements in .httaccess files. Here’s an example of how to use Redirect:

Apache configuration option

Redirect /username

If no argument is given, Redirect sends a temporary (302) status code, and the client is informed that the resource available at /username has temporarily moved to

No matter where they are located, Redirect statements must specify the full file path of the redirected resource, following the domain name. These statements must also include the full URL of the resource’s new location.

You can also provide an argument to return a specific HTTP status:

Apache configuration option

Redirect permanent /username
Redirect temp /username
Redirect seeother /username
Redirect gone /username

permanent tells the client the resource has moved permanently. This returns a 301 HTTP status code.

temp is the default behavior, and tells the client the resource has moved temporarily. This returns a 302 HTTP status code.

seeother tells the user the requested resource has been replaced by another one. This returns a 303 HTTP status code.

gone tells the user that the resource they are looking for has been removed permanently. When using this argument, you don’t need to specify a final URL. This returns a 410 HTTP status code.

You can also use the HTTP status codes as arguments. Here’s an example using the status code options:

Apache configuration option

Redirect 301 /username
Redirect 302 /username
Redirect 303 /username
Redirect 410 /username

Permanent and temporary redirects can also be done with RedirectPermanent and RedirectTemp, respectively:

Apache configuration option

RedirectPermanent /username/bio.html
RedirectTemp /username/bio.html

Redirects can be made with regex patterns as well, using RedirectMatch:

Apache configuration option

RedirectMatch (.*)\.jpg$$1.jpg

This matches any request for a file with a .jpg extension and replaces it with a location on a given domain. The parentheses allow you to get a specific part of the request, and insert it into the new location’s URL as a variable (specified by $1, $2, etc.). For example:

A request for will be redirected to and

A request for will be redirected to

Byla tato odpověď nápomocná? 0 Uživatelům pomohlo (0 Hlasů)