I had enable the RewriteRule to redirect visitors to www.example.com, however today I discovered the example rule that comes with D7 does not catch everthing, basically just example.com.

While doing some searching and testing on google I discovered links to one of my sites that looked like www.ww.example.com/*. When clicking on them the correct page opened, but the URL in the browser still started with www.ww. Not only that, every internal link had the same pattern as well so a user coming to the site would then browse around with www.ww.example.com stuck, and also cached for them.

Now, as i understand it, with help from KW|Meimi in the #drupal-se, the example rules that D7 comes for is so they will work with multisite installations on the same Drupal installation. That's of course good, but my problem will happen for them as well.

For now I simply took the D6 rules and they fixed this problem, but that means I hard coded in the domain name. Thats fine for me as its a single site though...

Comments

kristofferwiklund’s picture

As I and tsvenson discussed on IRC. In a single site setup this could work

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

But this hardcodes the URL in the .htaccess and doesn't work with multi-site setup. It could be nice to have it in the comments thou.

xibun’s picture

for our server we had to modify the solution offered in comment #1 to this:
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ http://www.example.com%{REQUEST_URI} [R=301,L]

dcam’s picture

Issue summary: View changes
Status: Active » Fixed

It sounds like this was solved.

tsvenson’s picture

Status: Fixed » Active

@dcam Not really, the suggestions in #1 and #2 only covers how to fix it after installing Drupal.

The identified problem still remains in the current code.

If Drupal 8 uses the same .htaccess file, then the scenario in the OP should apply there too.

dcam’s picture

Ok. If there's an actual problem here that should be solved by Drupal then that's fine.

As you note twice in the issue summary (OP), the .htaccess rules included with core are examples. Many people have to change them. I've had to in the past as well. There's been talk about renaming it to example.htaccess or something similar. See #1170538: Rename core .gitignore file to example.gitignore and add explanatory comments. I know it says it's about .gitignore, but if you search it you'll find a lot of talk about .htaccess as well.

So is this a case where your particular server needed some additional configuration (which is what it looked like to me, I'm sorry if it's not) or is there something we should fix about the .htaccess file?

tsvenson’s picture

Well, it's more the case that the rule supplied for Drupal 6 did not cause this problem, the changes introduced in Drupal 7 did however.

I just feel it is not a good thing to have an example rule that behaves in this way supplied. Either go back to the old or add help-text notifying of this possibility.

vashikaranallproblem’s picture

what is the solution of this problem can someone give me exact solution??

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.