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

Jooblay.net’s picture

This 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 :)

GBurg’s picture

hi, 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.

Jooblay.net’s picture

What is the root directory path of your drupal-site && and what is the root directory path of drupal-site-subdomain. :)

GBurg’s picture

For the domain (drupal):
/home/domain/public_html/

and for the subdomain (not drupal):
/home/domain/public_html/sub

Jooblay.net’s picture

!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 :)

jenlampton’s picture

I'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?

jenlampton’s picture

Version: 7.26 » 7.x-dev
Component: routing system » other
Category: Feature request » Bug report
Issue tags: -.htaccess, -subdomain

update

jenlampton’s picture

Here are the rewrite rules in Drupal 6 that did not have the subdomain problem:

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

And here are the problematic rewrite rules in Drupal 7:

  # RewriteCond %{HTTP_HOST} !^www\. [NC]
  # RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

This seems to work for me locally:

RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http%{ENV:protossl}://www.%{HTTP_HOST}/$1 [L,R=301]
kumaratulesh’s picture

Here 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]

ajayg’s picture

I 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.

Anybody’s picture

Category: Bug report » Support request
Status: Active » Closed (works as designed)

Closing 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.