Score:0

Redirect web service

cn flag

I have a web server that is running. There is a URL https://www.example.com/test/ (/var/www/html/test) How do I make https://test.example.com redirect to there?

I am using Apache 2.4 as my web daemon.

Score:0
in flag

There are a couple of ways to do this depending on your Apache configuration and how the code that runs the site has been written. That said, the most basic method would be to set an .htaccess rule.

Assumptions:

  1. The test.example.com has its own Apache configuration file (meaning that no other configurations will interfere with it)

  2. Apache has been configured to follow .htaccess rules

    Note: If one or both of these assumptions is not met by the web server, then you can stop reading as everything below this disclaimer will be "wrong".

Setting Up the Redirect

  1. Create or edit the .htaccess file:

    sudo vi /var/www/html/test/.htaccess
    

    Note: Feel free to use any text editor that you prefer.

  2. Paste the following into the file. This should be the only content in the file:

    Options +MultiViews +FollowSymLinks
    Options -Indexes
    
    Redirect 301 / https://www.example.com/test/
    
  3. Save the file

    There will be no need to restart or reload Apache. Test the redirect in a browser of your choice.

cn flag
For your first point, do you mean adding a new virtual host using the Apache conf files?
in flag
I don't know if you need to add a config file. There are dozens of different ways a person might configure Apache. The assumptions section was put there to make it clear that if your configuration differs from the two conditions, additional work will be required on your part
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.