David G David G - 5 months ago 13
PHP Question

Laravel 4 home redirecting to www.ipaddress and failing

My current .htaccess file looks like this:

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>


I have laravel 4 installed on an ubuntu 14.04 distribution.
My apache.config file looks like this:

<Directory />
Options FollowSymLinks
AllowOverride All
Require all denied
</Directory>

<Directory /usr/share>
AllowOverride None
Require all granted
</Directory>

<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>


And my 000-default.config is as follows:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/public
<Directory /var/www/public>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>


Laravel's installed in /var/www
What I experience however is that when I try to navigate to the IP of the site (no domain attached). I get redirected to www.ip_address
for example 178.1.2.3 would have me redirect to www.178.1.2.3.

Mod_rewrite is enabled. So I have no idea why this is happening.

Could anybody help?

Thanks

Answer

If it's redirecting, so it's not rewrite problem, the problem with redirecting.

If You navigate to: http://178.1.1.1 and as result You're in http://www.178.1.1.1 so it means in Your code somewhere redirection happens.

it's not apache issue, it's in laravel app code.

To prove it You can put in /var/www/public/index.php after <?php:

die($_SERVER['REQUEST_URI']);

it will show You that web server rewrites properly.

You've to find such code where it redirects and comment it.

Normal app must not redirect to www.HOSTNAME, redirection must be in web server level, not in app level.

Comments