I'm trying to configure virtual host in apache2 in ubuntu instance hosted with aws and successfully redirected the requests to the appropriate website.

Further clicking on the links on the index page changes the url in the browser to ip/mydomain.com/uri where i expect it to be mydomain.com/uri.

Here are the things i've done

  • Purchased mydomain.com from GoDaddy
  • Edited A record to ip (public ip of the aws instance)
  • Hosted ubuntu instance with aws and installed apache2,php,mysql
  • Created a site with wordpress and installed on the aws instance
  • Configured Virtual Host Entries under /etc/apache2/sites-enabled/mydomain.com.conf


<Directory "/var/www/html/mydomain.com/">
   DirectoryIndex index.php index.cgi index.html

<VirtualHost *:80>
   ServerName mydomain.com
   ServerAlias My Domain 
   ServerAdmin contact@mydomain.com
   RewriteEngine on
   DocumentRoot "/var/www/html/mydomain.com/"
   LogLevel warn
   ServerSignature Off

And enabled the site and restarted apache using the following commands

$ sudo a2ensite mydomain.com.conf
$ sudo service apache2 restart

Expected and Actual Behaviour

  1. www.mydomain.com should load http://ip/mydomain.com/index.php (working fine)
  2. Clicking on the internal link say contactus should redirect and url should be www.mydomain.com/contactus, but now it is http://ip/mydomain.com/contactus

Thanks for any references and support on this.

Note: I'm pretty new to this area so incase you feel this question is not clear kindly suggest improvements on comment before downvoting. That will help me improve this.

  • what's the difference between http://ip and http://myip one is the server's and the other is the clients? – Marcel Mar 5 at 16:43
  • @Marcel, am sorry, both are same, i'll fix it now. – Vivek Mar 6 at 11:28
  • 1
    Your ServerAlias statement is incorrect. It should match a DNS name which points to the IP address as well. E.g. when both example.com and www.example.com point to the same IP address of your web server, the primary will the the ServerName and others will be listed in ServerAlias. – Tommiie Mar 6 at 11:43
  • Also, it should redirect to http://<ip-address>/<domain-name>/. If that is really the case, that is some weird behavior. – Tommiie Mar 6 at 11:44
  • @Tommiie ServerAlias is just a name right, anyway i'll try to change that. Don't misunderstand on domain-name. Remember mydomain.com is the folder contains the site content. Its nothing but the URI to the index.html – Vivek Mar 6 at 12:34

Most probably it's WordPress itself generating the wrong URLs.

  • Go to your WordPress dashboard, Settings -> General.
  • Enter the correct URL in the WordPress Address field
  • Click on Save Changes
  • Go to Settings -> Permalinks
  • Click on Save Changes
    (You don't have to change anything here, saving the settings causes all post URLs to be regenerated)

Now WordPress should generate the correct URLs.

  • Hi gerald, earlier it was ip/mydomain.com, i updated with myurl.com. It didn't work, the page got crashed and i'm not able to go back to that admin page again. – Vivek Mar 6 at 12:33
  • Well, then you should fix that problem first. – Gerald Schneider Mar 6 at 12:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.