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.

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.

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
  • 414
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]`