David G David G - 1 year ago 69
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]

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 /usr/share>
AllowOverride None
Require all granted

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

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

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 would have me redirect to www.

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

Could anybody help?


Answer Source

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

If You navigate to: and as result You're in http://www. 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:


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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download