Author Topic: [Solved] Canonical URLs  (Read 2515 times)

akhasis

  • Zen Apprentice
  • *
  • Posts: 39
  • Karma: +1/-0
    • View Profile
[Solved] Canonical URLs
« on: July 17, 2012, 11:03:15 am »
Hello,

I'm just starting to work with Zentyal server for the first time, so maybe my question is quite trivial, but I could find no info about it.

I'm trying to get a webpage hosted in my Zentyal http server to work both through mypage.mydomain.com and www.mypage.mydomain.com.

I have been messing with the DNS configuration for my page and its aliases and managed to get both URL's to work, though for some reason the www url points to a different folder than the one without www (actually, I cant find out where the www url is pointing to).

Could somebody help me with this configuration?

Thanks in advance
« Last Edit: July 21, 2012, 09:15:36 am by Escorpiom »

Escorpiom

  • Zen Hero
  • *****
  • Posts: 897
  • Karma: +25/-1
    • View Profile
Re: Canonical URLs
« Reply #1 on: July 17, 2012, 12:18:06 pm »
Hi Akhasis,

That's normally done by setting the DNS records, in my case the people who registered my domain have both entries configured in their DNS servers,
with "www" and without "www".
Who is maintaining your DNS records?

Cheers.
Marcus' Rule:
Blanks & capitals = avoid it and you'll avoid problems...

robb

  • Guest
Re: Canonical URLs
« Reply #2 on: July 17, 2012, 12:40:28 pm »
I resolved this the following way:
For my domain I can add A, CNAME, TXT and MX records through a webinterface provided by the registrar I use.

I set up a zentyal.me ddns dynamic redirection service.
At the webinterface of the registrar I created a CNAME record pointing to zentyal.me ddns.
In your modem/router you forward port 80 to your zentyal server
done.

innocenti_jr

  • Zen Monk
  • **
  • Posts: 98
  • Karma: +9/-0
    • View Profile
Re: Canonical URLs
« Reply #3 on: July 17, 2012, 02:28:48 pm »
Also have a look at the ServerAlias directive in:
/etc/apache2/sites-available/user-ebox-YourVHostHere/*.conf
which you should add to your vhost.
"The problem with quotes on the Internet is that it is hard to verify their authenticity." - Abraham Lincoln

robb

  • Guest
Re: Canonical URLs
« Reply #4 on: July 17, 2012, 05:33:28 pm »
With Zentyal that works a little different. Manual changes to .conf files will be overwritten after reboot or service restart. Have a read here: http://trac.zentyal.org/wiki/Documentation/Community/HowTo/CustomizeConfigFiles

Easiest way is to use the webserver module.
« Last Edit: July 17, 2012, 05:35:15 pm by robb »

innocenti_jr

  • Zen Monk
  • **
  • Posts: 98
  • Karma: +9/-0
    • View Profile
Re: Canonical URLs
« Reply #5 on: July 17, 2012, 08:41:22 pm »
Hi Robb!
You're right, almost everything gets overwritten by Zentyal, but not the file I mentioned (that's what it's for: allowing custom settings for vhosts).
I do not know how skilled the topic starter (akhasis) is, but possibly he knows a bit about Apache.
If Apache is configured to have a vhost called "mypage.mydomain.com", the mentioned directive allows him to put just a "ServerAlias www.mypage.mydomain.com" in the mentioned file and he's done.
AFAIK the Apache directive "ServerAlias" is not handled by Zentyal -- a pity.

BTW: JosĂ©'s CustomizeConfigFiles document mentions me (look at the end); I am the mentioned Oliver who delivered the patch to allow the customization of *.mas files.  ;)
« Last Edit: July 17, 2012, 08:46:21 pm by innocenti_jr »
"The problem with quotes on the Internet is that it is hard to verify their authenticity." - Abraham Lincoln

akhasis

  • Zen Apprentice
  • *
  • Posts: 39
  • Karma: +1/-0
    • View Profile
Re: Canonical URLs
« Reply #6 on: July 18, 2012, 09:37:05 am »
Thank you all for your advice, but I can't manage to solve my problem. I'll let you know more about what I need and what I have done already:

I have a web application working on my Zentyal server. It can be accessed through the url mypage.mydomain.com/nameoftheapplication/public/.

Since I want to make it easier for the users of the application to access it, I needed to change the documentroot for mypage.mydomain.com to point to the public directory. To do so, I created the file /etc/apache2/sites-available/user-ebox-mypage.mydomain.com/documentroot with the right documentroot directive. Now, when I go to mypage.mydomain.com, the homepage of my application is displayed.

Now, what I need is to get the same behavior when I go to www.mypage.mydomain.com (that is, access the same homepage). As of now, when I go to that last URL, I get the message

Quote
It works!

This is the default web page for this server.

The web server software is running but no content has been added, yet.

(I don't know if it's a default behavior of Zentyal because as far as I can tell, there is no www alias configured for this domain).

I think that what I am trying "the Zentyal way" would be accomplished like this in a non-zentyal web server:

Code: [Select]
<VirtualHost *>
  ServerName mypage.mydomain.com
  ServerAlias www.mypage.mydomain.com
  DocumentRoot "/srv/www/mypage.mydomain.com/nameoftheapplication/public/"
</VirtualHost>

I have looked all around the Zentyal interface, and I guess there must be something at the DNS section to make the www URL point to the same folder than the non-www URL, but can't find it (answering innocenti_jr, I'm not very experienced at managing Apache, though up to now I've been able to google my way).

I expect I made my case clearer (instead of more messy, with so much info). I'm also glad to have users endorsed by Zentyal staff trying to help me.

Thanks again for your attention :D


robb

  • Guest
Re: Canonical URLs
« Reply #7 on: July 18, 2012, 11:41:04 am »
What about creating a CNAME for www.yourdomain.tld pointing to yourdomain.tld in DNS of your registrar?

innocenti_jr

  • Zen Monk
  • **
  • Posts: 98
  • Karma: +9/-0
    • View Profile
Re: Canonical URLs
« Reply #8 on: July 18, 2012, 11:42:01 am »
Please post the output of these commands:
Code: [Select]
dig mypage.mydomain.comand:
Code: [Select]
dig www.mypage.mydomain.com
"The problem with quotes on the Internet is that it is hard to verify their authenticity." - Abraham Lincoln

christian

  • Guest
Re: Canonical URLs
« Reply #9 on: July 18, 2012, 11:48:37 am »
Good point to look at "dig" result. Still to make it accurate, this has to be done from internal network and perhaps from internet too if some users are accessing from "outside". And result can be somewhat different.

Then another aspect is virtual server Apache side. As you rightly pointed, alias is cool  ;)

akhasis

  • Zen Apprentice
  • *
  • Posts: 39
  • Karma: +1/-0
    • View Profile
Re: Canonical URLs
« Reply #10 on: July 20, 2012, 09:19:36 am »
    Hello,

    This is my configuration right now:

    Domains:
    • mydomain.com (its IP address is pointing to an external server where our webpage is hosted).

      Machine names:
      • ns (pointing to the same IP as above)
      • mypage (pointing to the IP of our internal web server so that when you go to mypage.mydomain.com a webpage different from the one above is displayed).
        Alias
        • www.mypage (again pointing to the internal webserver IP)

Just for you to remember, what I'm trying to do is get www.mypage.mydomain.com to point to the same webpage where mypage.mydomain.com is already pointing. If possible, following Zentyal philosophy instead of using workarounds.

I got the results of the DiG command as you asked (edited to match my "mypage.mydomain.com" example):

from outside our network:

Code: [Select]

; <<>> DiG 9.8.1-P1 <<>> www.mypage.mydomain.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 3880
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;www.mypage.mydomain.com. IN A

;; ANSWER SECTION:
www.mypage.mydomain.com. 86400 IN A X.Y.58.10

;; Query time: 56 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Jul 20 07:37:51 2012
;; MSG SIZE  rcvd: 53




; <<>> DiG 9.8.1-P1 <<>> mypage.mydomain.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 56975
;; flags: qr rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 0, ADDITIONAL: 0

;; QUESTION SECTION:
;mypage.mydomain.com. IN A

;; ANSWER SECTION:
mypage.mydomain.com. 86357 IN A X.Y.58.10

;; Query time: 1452 msec
;; SERVER: 127.0.0.1#53(127.0.0.1)
;; WHEN: Fri Jul 20 07:37:25 2012
;; MSG SIZE  rcvd: 49


From the in side:

Code: [Select]

; <<>> DiG 9.5.1-P2 <<>> www.mypage.mydomain.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 32496
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;www.mypage.mydomain.com. IN A

;; ANSWER SECTION:
www.mypage.mydomain.com. 259200 IN CNAME mypage.mydomain.com.
mypage.mydomain.com. 259200 IN A 10.0.0.155

;; AUTHORITY SECTION:
mydomain.com. 259200 IN NS ns.mydomain.com.

;; ADDITIONAL SECTION:
ns.mydomain.com. 259200 IN A X.Y.129.117

;; Query time: 0 msec
;; SERVER: 10.0.0.155#53(10.0.0.155)
;; WHEN: Fri Jul 20 09:42:13 2012
;; MSG SIZE  rcvd: 100





; <<>> DiG 9.5.1-P2 <<>> mypage.mydomain.com
;; global options:  printcmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 14309
;; flags: qr aa rd ra; QUERY: 1, ANSWER: 1, AUTHORITY: 1, ADDITIONAL: 1

;; QUESTION SECTION:
;mypage.mydomain.com. IN A

;; ANSWER SECTION:
mypage.mydomain.com. 259200 IN A 10.0.0.155

;; AUTHORITY SECTION:
mydomain.com. 259200 IN NS ns.mydomain.com.

;; ADDITIONAL SECTION:
ns.mydomain.com. 259200 IN A X.Y.129.117

;; Query time: 0 msec
;; SERVER: 10.0.0.155#53(10.0.0.155)
;; WHEN: Fri Jul 20 09:42:00 2012
;; MSG SIZE  rcvd: 82



Thank you everybody again for your attention
« Last Edit: July 20, 2012, 10:14:50 am by akhasis »

innocenti_jr

  • Zen Monk
  • **
  • Posts: 98
  • Karma: +9/-0
    • View Profile
Re: Canonical URLs
« Reply #11 on: July 20, 2012, 12:09:04 pm »
Ok, if I read your post correctly your DNS settings are fine.
I also assume that a further check with ping:
Code: [Select]
ping mypage.mydomain.com
ping www.mypage.mydomain.com
results in "10.0.0.155" from your LAN and "X.Y.58.10" from the internet.

If that's the case, there's something wrong with Apache.
How did you setup the vhost? With Zentyal or manually?
Either way, please post your vhost configuration file.
"The problem with quotes on the Internet is that it is hard to verify their authenticity." - Abraham Lincoln

akhasis

  • Zen Apprentice
  • *
  • Posts: 39
  • Karma: +1/-0
    • View Profile
Re: Canonical URLs
« Reply #12 on: July 20, 2012, 01:21:15 pm »
All the ping results are as expected except for

ping www.mypage.mydomain.com

(when pinged from inside mynetwork there's no response, from outside it is ok).

I setup my vhosts with Zentyal. It may sound silly, but I can't find the file where the vhost configuration is stored  :-[

It is starting to look like all my webserver configuration must be wrong. For example, the way it is configured, i think it wouldnt be possible to host a different website in the same machine under another subdomain (i.e. anotherpage.mydomain.com). I thought I was getting to something, but right now I'm totally lost.
« Last Edit: July 20, 2012, 01:26:08 pm by akhasis »

robb

  • Guest
Re: Canonical URLs
« Reply #13 on: July 20, 2012, 01:23:05 pm »
If it is not ok from the inside, you will have to make the necessary entry's in Zentyal DNS

akhasis

  • Zen Apprentice
  • *
  • Posts: 39
  • Karma: +1/-0
    • View Profile
Re: Canonical URLs
« Reply #14 on: July 20, 2012, 02:40:18 pm »
    Ok, I think I did it -- the Zentyal way!!

    Go to your Zentyal panel > web servers. Create 2 virtual hosts: mypage.mydomain.com and
www.mypage.mydomain.com. Automatically, Zentyal creates the corresponding directories for each page, and the necessary entries in the DNS section. Go to the DNS section and complete it like this:

Domains:
  • mydomain.com (its IP address is pointing to an external server where our webpage is hosted).

    Machine names:
    • ns (pointing to the same IP as above)
    • mywebserver (or whatever you want to call that 'physical' computer. Pointing to the internal webserver IP)
    • www.mydomain (again pointing to the external server)
    Alias
[/li]
[/list]
[/list]

This way, you can access via mydomain.com and www.mydomain.com to our main webpage, hosted in an external host; and our secondary webpage, hosted in our internal webserver, via mypage.mydomain.com. When you load www.mypage.mydomain.com it still loads a different page. Lets deal with it:

Go to /etc/apache2/sites-available/user-ebox-www.mypage.mydomain.com . There is where the custom configuration for that webpage can be stored.

Make a new file, call it documentroot (or whatever you like) and put in it:

Code: [Select]
DocumentRoot /srv/www/mypage.mydomain.com/
Now, both mypage.mydomain.com and www.mypage.mydomain.com are pointing to the same directory. You can even delete the directory Zentyal created to store the www.mypage.domain.com website files safely.

I hope this post is useful for somebody and saves them the time it took me (and you).

Thank you again for your help!