Is it possible to create path like subdomain for custom module menu?

For example create url like xyz.example.com if path is example.com/xyz where xyz is custom module menu.

I've already tried to use .htaccess file

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^xyz(.*) http://xyz.example.com/$1 [R=301,L]

It correctly changing url from example.com/xyz to xyz.example.com but xyz.example.com redirected me to HOME page of the site.

I just want to change the url from example.com/xyz to xyz.example.com where module result will be displayed.


EDIT : My requirement is similar to this

2 Answers 2


You could modify $_GET['q'] during hook_boot(), something like the following.

function mymodule_boot() {
  $_GET['q'] = implode('.', array_slice(explode('.',$_SERVER['HTTP_HOST']), 0, -2));

There is probably a regex that could do the same as that explode/implode mess, but that does the trick to start with.

  • Thanks. hook_init() worked for me. Under this hook i put the line if(preg_match('/xyz.example.com/', $_SERVER['HTTP_HOST'])) $_GET['q'] = implode('.', array_slice(explode('.',$_SERVER['HTTP_HOST']), 0, -2)); But it brought another problem. Some images appearing as broken and all content in Header and Footer disappeared. I suspect because domain has changed it's happening. Please can you suggest me how to deal with it. Apr 10, 2013 at 15:58
  • You're going to have to do some more debugging on your end to figure that out. Look at how the HTTP requests are being handled for the images, whether or not they are being redirected as well. As for the header/footer, you'll have to provide a lot more explanation as well.
    – JamesK
    Apr 10, 2013 at 23:54
  • Thanks again.. It works. After some modification in Header and Footer section blocks they are appearing correctly. Apr 15, 2013 at 11:53

$1 will be example.com/... not the module path that you want.

Specify the path as per:

RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^ mymenupath [R,L]

Where you say the menu (mymenupath) is set up in your custom module.

Log the rewrites in your apache config to verify where the redirects are going:

LogLevel alert rewrite:trace3
  • It's giving Internal Server Error saying - (The server encountered an internal error or misconfiguration and was unable to complete your request. Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request.) Apr 9, 2013 at 14:05
  • I didn't have a space between the replacement path and rewrite arguments. It is the same approach as yours, however ^ (match start of line ie anything) rewrite to mymenupath. No wildcard replacements.
    – Interlated
    Apr 10, 2013 at 0:11
  • I removed the space from RewriteRule ^mymenupath [R,L]. Now its saying page not found. Can you guide me how and where to use LogLevel alert rewrite:trace3. Apr 10, 2013 at 16:16
  • Since your defined menu item is probably not mymenupath the rewrite rule could be working. Change this to the path you want. The LogLevel directive goes inside the rewrite block. Put it just after where you have "RewriteEngine On". Guide is here httpd.apache.org/docs/current/mod/mod_rewrite.html
    – Interlated
    Apr 11, 2013 at 5:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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