Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi,
When enabling the redirect from domain.com to www.domain.com in the htaccess file, it will also redirect sub.domain.com to www.sub.domain.com . This is in general unintended behaviour and should be fixed (and I would also like a fix :))
Regards,
Geert
Comments
Comment #1
Jooblay.net CreditAttribution: Jooblay.net commentedThis is a configuration issue on your drupal-core/sub and drupal-core. Do you have your webserver pointing to to the correct root directory. Apache2 would be something like /var/www/drupal-core/.htaccess then sub would be var/www/drupal-core/sub/.htaccess unless your on a multi-site.
Either way your missing somthing. htaccess files should only effect a single install. Unless multi-site. Also you may want to look at even why if you are setting drupal-core/sub and not just create multiple subs as subs. /var/www/sub0.example.com
/var/www/example.com
/var/www/sub1.example.com :)
Comment #2
GBurg CreditAttribution: GBurg commentedhi, thanks for the reply.
I seem to have solved the issue by placing an empty .htaccess in my subfolder. (Could this be true?)
Thanks for your suggestions, I also like the idea to make it in a seperate websites.
Comment #3
Jooblay.net CreditAttribution: Jooblay.net commentedWhat is the root directory path of your drupal-site && and what is the root directory path of drupal-site-subdomain. :)
Comment #4
GBurg CreditAttribution: GBurg commentedFor the domain (drupal):
/home/domain/public_html/
and for the subdomain (not drupal):
/home/domain/public_html/sub
Comment #5
Jooblay.net CreditAttribution: Jooblay.net commented!indeed this is your issue. Are you on CentOS? You will need to set the root directory path to be absolute. I would guess that drupal thinks there is 2 installs in the same directories.
Not sure of your setup, but you can set roots in cpanel. And or apache2/sites-available
/home/domain/public_html
/home/subdomain/public_html
Above paths are recommended by us due to additional issues while developing. One being late nights and forgetting which directory your in :)
Comment #6
jenlamptonI'm having the same problem on all versions of Drupal 7.
I often set up beta sites that live in /var/www/beta along side my live sites that live in /var/www/html. Both sites are running off the same code base (same git repo).
If my beta sites have the domain name beta.mydomain.com and the default rewrite rule is uncommented in .htaccess. I get redirected to www.beta.mydomain.com in the beta site. This should not be the case.
I do not believe it is a server configuration issue, as it happens on all my servers (centOS and nginx) and on my localhost (mamp). I've been solving the problem for years by commenting out the Drupal 7 rewrite rules in .htaccess and copying in the ones from Drupal 6.
Can't we solve this issue with a smarter Rule in .htaccess?
Comment #7
jenlamptonupdate
Comment #8
jenlamptonHere are the rewrite rules in Drupal 6 that did not have the subdomain problem:
And here are the problematic rewrite rules in Drupal 7:
This seems to work for me locally:
Comment #9
kumaratulesh CreditAttribution: kumaratulesh commentedHere are the .htaccess rewrite rules for Drupal 7, add below two lines of code after " RewriteEngine on" under "":
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
Comment #15
ajayg CreditAttribution: ajayg as a volunteer commentedI have a similar issue after move. Not sure if they are related since it was working for several years but not working with newer versions of apache and php.
https://www.drupal.org/node/2874935
The rule mentioned by kumaratulesh in .htaccess is not working somehow which is very odd, despite mod_rewrite and other rules in htaccess working.
Comment #16
AnybodyClosing this as designed now, as it's an individual configuration step and there are several comments pointing out how it can be solved. Not a bug in core.