How to generate subdomains in Drupal URLs based on content type?

Events happening in the community are now at Drupal community events on www.drupal.org.
chadj's picture

I hope it's ok to post this here. I first posted this question in the support forums -- but it was suggested that I post here instead since it's a path question.

I'm totally new to Drupal but experienced in SEO and PHP. I've always rolled my own crappy CMS because of custom needs. I'm REALLY hoping Drupal will help me to stop this wasteful methodology.

The main thing I need to figure out is how to take full control of Drupal URLS. My future sites need simple URLs in the style of about.com wherein each subject or content type is assigned a unique subdomain (one site, many dynamic subdomains like http://dogs.about.com, http://cats.about.com).

All incoming subdomain links are directed to the base folder where an HTACCESS file does an internal URL re-write (no redirects) for Drupal. This part is easy for me so this is NOT a question about DNS or HTACCESS.

What I need to know is how to get Drupal/Path-auto etc. to generate (alias?) links using my pattern? Here's the URL pattern (with no subdomain for the default type "pages"):

  http://[content-type].domain.com/[pathauto-node-title].html

it would look something like this:

  pages:        http://domain.com/[node-title].html
  forums:       http://forum.domain.com/[node-title].html
  blogs:        http://blog.domain.com/[node-title].html
  articles      http://article.domain.com/[node-title].html
  news items:   http://news.domain.com/[node-title]-[date].html
  newsletters:  http://newsletter.domain.com/[node-title]-[date].html
  secure:       https://secure.domain.com/[node-title].html

I'm looking in Pathauto but it doesn't seem to allow defining the entire URL. I hope I'm just missing something obvious. Does the "alias" hold an entire URL or just the path part?

I've searched around in the forums and the other subdomain questions seem to deal with DNS, HTACCESS, redirecting etc. and not how to get Drupal to create links using the pattern. Perhaps this part is already too obvious?

Thanks,
Chad

Comments

paths

greggles's picture

Pathauto is really just a means to create paths. So, if this can be done with drupal core path.module then pathauto can do it.

Onfortunately, I think the only way to get that is using the htaccess tricks you mention above (which I frankly don't actually know that well).

--
Knaddison Family | mmm Free Range Burritos

path.module?

chadj's picture

The .HTACCESS part is really easy, you just use a Regex expression to grab the subodmain and reformat it into whatever format Drupal prefers.

The part I'm not clear about is how to get Drupal to generate the subdomain links. How can path.module be used to output urls in the form of http://[content-type].domain.com/[title] ?

I can look through the code myself if someone can point me at a good starting place. Where does Drupal construct URLs for links?

  • Chad

A good starting point...

pancho's picture

... might be the new localizer.module! It supports

language switching through hostname : it.example.com, en.example.com,...

While this is not exactly what you are looking for, I suspect that the way they do that subdomain switch is of great help for your problem... You can directly browse the module code at the CVS repository.

Hope this is of any help for you...
Pancho

Multidomain module

pancho's picture

Take a look at the Multidomain module. Isn't that exactly what you need?

Pancho

path.module

greggles's picture

it's generated in path.module

Take a look at function path_set_alias($path = NULL, $alias = NULL, $pid = NULL) { on line 135.

Greg

--
Knaddison Family | mmm Free Range Burritos

some documentation

greggles's picture

Partially as a result of your post, chad, I spent some time today writing and fixing up the pathauto documentation in the handbooks.

In particular I
Wrote this page of recipes that talks about patterns with static entries per content type: http://drupal.org/node/124462
And updated the page about "dangerous paths" http://drupal.org/node/73232

There's still lots of room for improvement, particularly on the "tips" page at http://drupal.org/node/86994

I encourage everyone who can (which is everyone...really...) to read the docs and help provide more pointers on how you like to setup pathauto. If you can't edit the book just comment on the page.

Thanks!
Greg

--
Knaddisons Denver Life | mmm Free Range Burritos

Did someone ever figure out

j0rd's picture

Did someone ever figure out how to do the subdirectly via content type?

I will be creating a drupal site with a forum, blog, windows programs and mac programs. I would like to put the forum, blog and mac programs each on their own subdomains each with unique homepages, but I would like to run this all off 1 Drupal installation.

Any ideas on how I can achieve this?


Freelance Web Design

That is the same point ...

David Naian's picture

Hi, subscribing. I stopped at the same stage of development. Being very intersted in the further approach of this. Cheers

.davidnaian

.davidnaian

Hello, we had a similar issue

Ivo.Radulovski's picture

Hello,

we had a similar issue so we used organic groups + subdomain

we have a group like news --> news.yourdomain.com

then we have group posts that are posted into news and they inherit the subdomain news.yourdomain.com/title-of-your-post

the settings are done in pathauto -> if you need info on the pathauto settings let me know...

Best!

-----

Drupal Development by Trio Interactive

you are the maaan

huslabs's picture

you are the maaan

Please do it!

pepe-perez's picture

@segments
Yes please post the settings.
But much more I need the settings of the subdomain Module, or better, of the Apache and .htaccess
I use XAMPP for develop, but I have no idea how to get the domains and subdomains working there.
I has install the subdomain Module and I got a lot of errors... DNS, Wildcard, Drupal's inbound URL rewriting and last but not least, $cookie_domain in settings.php

I do not have any Idea what to do.
And please, if you have some tip for the Shared Hoster to...
Thanks for your help!

Please do it!

pepe-perez's picture

@segments
Yes please post the settings.
But much more I need the settings of the subdomain Module, or better, of the Apache and .htaccess
I use XAMPP for develop, but I have no idea how to get the domains and subdomains working there.
I has install the subdomain Module and I got a lot of errors... DNS, Wildcard, Drupal's inbound URL rewriting and last but not least, $cookie_domain in settings.php

I do not have any Idea what to do.
And please, if you have some tip for the Shared Hoster to...
Thanks for your help!

I am also having the issue, please help me.

thelionkingraja's picture

@segments
@pepe-perez

I am also having the same issues.

I have Groups using OG, i need to have subdomains for each group created.

I have tried using OG + pathauto + subdomains in my localhost. I got the following errors.

DNS server - show/hide details Not working yet
test-1.localhost failed to resolve
test-2.localhost failed to resolve
test-3.localhost failed to resolve
It appears your DNS server is not setup to handle wildcard subdomains (*.localhost) for localhost. Edit the DNS zone file or settings for your server to fix.

PHP caches DNS lookups, so you'll want to restart your web server after making changes to your DNS server to see the results of your changes on this page.

Web server unable to test
Unable to test Apache settings until DNS wildcard subdomains are working
Drupal's inbound URL rewriting - show/hide details Not working yet
HTTP request to http://subdomain-test.localhost/groups/subdomain/test resulted in an internal Drupal path of . It should have been ~subdomain-test/subdomain/test
The custom_url_rewrite_inbound() function in settings.php is rewriting the internal path incorrectly. Did you patch settings.php? See readme.txt for instructions.

Drupal's outbound URL rewriting - show/hide details  Working
$cookie_domain in settings.php - show/hide details  Set

Please help me to fix this issues.

Thanks

suggest me please.......!

nilofar123's picture

Hi,
I have create a mobile site using adaptive theme . I use XAMPP for develop now i want use this mobile site for my website can you please suggest me what i do now. Can i use sub domain module for that purpose?

I don't Know anything about that,if anybody knows about using sub domain for mobile theme please give your suggestion.

Thank you.

nathan tsai's picture

If you just want access to the file, just do a relative path with a forward slash in front!

"/[pathauto-node-title].html" will go to the path regardless of the subdomain.

Hopes that helps someone.

Paths

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds:

Hot content this week