Tell me more ×
Drupal Answers is a question and answer site for Drupal developers and administrators. It's 100% free, no registration required.

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.

Thanks.

EDIT : My requirement is similar to this

share|improve this question

2 Answers

up vote 2 down vote accepted
+50

I've never tried this, but can you modify $_GET['q'] during hook_boot()? If so, you can do something like:

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.

share|improve this answer
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. – Vikas Naranje Apr 10 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 at 23:54
Thanks again.. It works. After some modification in Header and Footer section blocks they are appearing correctly. – Vikas Naranje Apr 15 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
share|improve this answer
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.) – Vikas Naranje Apr 9 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 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. – Vikas Naranje Apr 10 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 at 5:37
Thanks for guiding me. – Vikas Naranje Apr 15 at 11:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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