3

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

Configuration:

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

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

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.

Tommiie
  • 5,627
  • 2
  • 12
  • 46
Vivek
  • 93
  • 8
  • what's the difference between `http://ip` and `http://myip` one is the server's and the other is the clients? – Marcel Mar 05 '19 at 16:43
  • @Marcel, am sorry, both are same, i'll fix it now. – Vivek Mar 06 '19 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 06 '19 at 11:43
  • Also, it should redirect to `http:////`. If that is really the case, that is some weird behavior. – Tommiie Mar 06 '19 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 06 '19 at 12:34
  • `ServerAlias` is _not_ just a name: https://httpd.apache.org/docs/2.4/mod/core.html#serveralias – Tommiie Mar 06 '19 at 12:36
  • The first matching ServerName or ServerAlias is used, with no different precedence for wildcards. So i think serverName will solve the purpose, serverAlias is only when multiple names are pointing to single virtualhost. – Vivek Mar 06 '19 at 13:16

1 Answers1

1

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.

Gerald Schneider
  • 23,274
  • 8
  • 57
  • 89
  • Hi gerald, earlier it was http://ip/mydomain.com, i updated with http://www.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 06 '19 at 12:33
  • Well, then you should fix that problem first. – Gerald Schneider Mar 06 '19 at 12:34