3

I have a Google Cloud Compute instance running a Bitnami Magento stack. For some strange reason if I try to browse to the site via the IP address it prefixes the IP address with www. so fails. The site domain name is fine.

This is relevant because you can only access phpmyadmin on a bitnami stack from 127.0.0.1 (after creating an SSH tunnel). Problem is this is being redirected to www.127.0.0.1 and fails.

I can't find anything in the apache2 conf files that account for this behaviour. Magento itself is setup correctly and works fine. The problem began after discovering a rogue package had been uploaded (this has since been cleaned).

Any ideas greatfully received, it's driving me nuts.

  • @mootmoot: They're traversing an SSH tunnel using local port forwarding before connecting to the loopback interface on the remote server. – Paul Calabro Jul 27 '16 at 11:34
  • Do you have any .htaccess files in your webroot folder? Grep for www in any .htaccess files, as you could have some redirect there – ralz Jul 27 '16 at 11:35
  • @PaulCalabro : I think he misunderstood the server resolution. When 127.0.0.1 request send to the server, the rest of the redirect (even to funny name) will be done by the server. – mootmoot Jul 27 '16 at 11:36
  • Just use your hosts file to point your domain names to 127.0.0.1. Then this won't happen. – EEAA Jul 27 '16 at 12:22
  • 3
    Bitnami-related questions are [off-topic on Server Fault](http://meta.serverfault.com/a/8840/20815). – EEAA Jul 27 '16 at 20:43

3 Answers3

2

It sounds like either the work of mod_rewrite or the Redirect directive. I would grep for the RewriteCond and Redirect in your Apache configs.

More info. can be found here.

Paul Calabro
  • 530
  • 5
  • 12
2

As Paul said this is likely mod_rewrite. My guess would be that there is a .htaccess file in the webroot somewhere responsible for this rule.

the rule you are looking for should look something like this:

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

Editing this to something like:

RewriteEngine On RewriteCond %{REMOTE_ADDR} !=127.0.0.1 RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ %{HTTP_HOST}%{REQUEST_URI} [R=301,L]

This "translated" would basically say "when the remote address is not 127.0.0.1 do the rewrite rule".. hope thats the solution for you.

cormpadre
  • 404
  • 2
  • 5
  • I found this in an apache conf file. How can exclude IP address 127.0.0.1 ? RewriteEngine On RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L] – user1563720 Jul 27 '16 at 12:31
  • That says something like "if HTTP_HOST is not www.something rewrite to %.HTTP_HOST"... (in this context im 90% sure it refers to "www")..so removing this rule or commenting it out (much safer) should allow you to test. As the rule is in the config files you will need to reload or restart apache after the change... Note: I dont know how this will affect your website software. – cormpadre Jul 27 '16 at 13:22
  • The ReWrite rule above is indeed responsible for the issue. How can I exclude IP address 127.0.0.1 from the rule? – user1563720 Jul 27 '16 at 14:39
  • Adding an extra line to that rule like this should achieve what you want but should be tested: `RewriteEngine On RewriteCond %{REMOTE_ADDR} !=127.0.0.1 RewriteCond %{HTTP_HOST} !^www\. [NC] RewriteRule ^(.*)$ %{HTTP_HOST}%{REQUEST_URI} [R=301,L] ` – cormpadre Jul 28 '16 at 10:17
1

You can configure this in .htaccess which should present in root directory of your web server.

following code will redirect your site from yourdomain.com to www.yourdomain.com

`RewriteEngine on
 # Redirect to domain with www.
 RewriteCond %{HTTPS} off
 RewriteCond %{HTTP_HOST} !^www\. [NC]
 RewriteRule .* http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
 # Same for HTTPS:
 RewriteCond %{HTTPS} on
 RewriteCond %{HTTP_HOST} !^www\. [NC]
 RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]`