Hi, I have a question about redirecting Drupal when it's installed in the sub-directory of an add-on domain. I looked around the forum and searched on Google, but can't seem to find a thread that is related to this situation (most of them are on multi-sites or redirecting from sub-dir to root), I'm sorry if this has been previously discussed, in which case please do point me to the correct place ^^;

Anyways, I have Drupal installed in the sub-directory of an add-on domain, so the directory structure looks like this:

public_html/addon.com/drupal/

While to users the site would appear as follows:

addon.com/drupal/

Since CPanel treats the add-on domain as a subdomain, sometimes Google is indexing the site as a subdomain like this:

addon.site.com/drupal/ (instead of addon.com/drupal/)

I tried doing a redirect in .htaccess with the following:

RewriteCond %{HTTP_HOST} ^addon.site.com/drupal
RewriteRule ^(.*)$ http://www.addon.com/drupal/$1 [R=301,L]

But the redirect is not working.

I tried changing base_url in setting.php to "addon.com/drupal", and uncommenting the line "RewriteBase /drupal" in .htaccess (note I also uncommented the part in .htaccess that allows users to access the site with the 'www.' prefix), but that didn't help either.

Am I not redirecting correctly, or is there something else in Drupal that should be changed which I failed to notice?

Thanks!

Comments

Anonymous’s picture

Well, solved it. Apparently if I uncomment Drupal's own redirect rules in the .htaccess file, my own rules don't work, so I just commented out the redirects in .htaccess (basically left everything as is without uncommenting anything), then did my own www and subdomain redirect:

RewriteCond %{HTTP_HOST} ^subdomain.domain.com [NC]
RewriteRule (.*) http://www.subdomain.com/drupal/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^www.subdomain.domain.com [NC]
RewriteRule (.*) http://www.subdomain.com/drupal/$1 [R=301,L]