What is the best approach to redirect to

Posted December 17, 2016 1.8k views
UbuntuMiscellaneous is hosted here on DO. is hosted somewhere else.

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
1 answer

If you’re using Apache, you can use Rewrite rules to rewrite to

You can add following to your Virtual Host or .htaccess for

RewriteEngine on 
RewriteRule ^forum/(.*)$ $1

If you changed via Virtual Host make sure restart Apache after change. If you go with .htaccess, make sure it’s enabled.
This will ‘just remove’ forum/ part from your link.

If you decide to go with Virtual Host change, it will look something like:

<VirtualHost *:80>
    RewriteEngine on 
    RewriteRule ^forum/(.*)$ $1
    . . .

You can find virtual hosts files in /etc/apache2/sites-available. Default file is 000-default.conf.

You can also go with redirection, but rewrite rules should be more suitable.

If you use nginx, I can write down instructions too, if needed.

by Mateusz Papiernik
HTTP redirection is a way to point one domain or address to another. There are a few different kinds of redirects (301 Moved Permanently and 302 Found), each of which mean something different to the client browser. You can create a redirect in Apache by adding `Redirect /oldlocation` to the virtual host entry in the server configuration file. This guide will cover a more in depth explanation of how to implement each kind of redirect in Apache.