Laravel 4 home redirecting to www.ipaddress and failing - apache

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

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.

Related

How to fix " Not found " when refresh page with vue js SPA in Apache Server?

I just deploy my vue js project to apache server. My file /dist located in /var/www/html/dist. When i visit the page it's work fine. But when i visit in another page and i refresh the page, in browser say 404 Not found. How can i fix this ?
You need a configuration something similar to this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
It will automatically serve index.html file for every request that doesn't have a corresponding static file. You will have to put this .htaccess file. The use of IfModule is explained here.
I have same error, on ubuntu after i install apache.
First i added in /etc/apache2/apache2.conf
AllowOverride All
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
In /etc/apache2/sites-available
<VirtualHost test.ru:80>
ServerName www.test.ru
ServerAlias test.ru
ServerAdmin webmaster#localhost
DocumentRoot /var/www/test.ru
<Directory /var/www/test.ru>
#Разрешение на перезапись всех директив при помощи .htaccess
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Then in console activate rewrite module and restart apache
sudo a2enmod rewrite
service apache2 restart

Not able to access laravel routes in apache2 server

I've deployed a new laravel installation to my server, While doing so I configured my apache2 as following:
I added 000-default.conf file in /etc/apache2/sites-available/ as following:
DocumentRoot /var/www/html
<Directory /var/www/html/>
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
Require all granted
</Directory>
I've my laravel installed into /var/www/html/stellar folder now I access my installation through:
http://52.39.175.55/stellar/public/
But while calling the routes it is not working, Like
http://52.39.175.55/stellar/public/oauth/token
Here is the screenshot:
But suppose I call through this:
http://52.39.175.55/stellar/public/index.php/oauth/token
I get the access,
I tried changing my public/.htaccess file to something like this:
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /stellar
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
Still there is no change, Help me out in this.
Your VirtualHost on /etc/apache2/sites-available/ should look like this:
<VirtualHost *:80>
DocumentRoot "/var/www/html/stellar/public"
ServerName yourdomain.com
<Directory /var/www/html/stellar/public>
AllowOverride All
</Directory>
</VirtualHost>
Then restart apache2 and it should work.
I hardly recommend you to duplicate the 000-default.conf file, rename it and include the VirtualHost, then enable it with a2ensite command, just because it's more easy to manage.

Apache2 rewrite doesn´t work

I am making a test with codeigniter and I make this .htaccess:
#Options +FollowSymLinks
#Options -Indexes
DirectoryIndex index.html index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|css|Scripts|images|uploads)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
On the config files of apache where is necessary make many changes, I have this (only what I think is important for this case):
/etc/apache2/apache2.conf
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
/etc/apache2/site-available/000-default.conf
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
<Directory />
#Options FollowSymLinks
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order deny,allow
Allow from all
</Directory>
The path where the codeigniter is installed is in /var/www/html/test, and if on browser I make http://ejemplo.com/test the wellcome controller of igniter works, but if I try to access to other function on this controller I get a 404 (make by apache, not the 404 from codeigniter).
Do I forget something?? What am I doing wrong??
Thank you.
PS:The codeigniter is an empty and new installation (only a helloworld function on the wellcome controller).

Non-existing file/URL returns 403 Forbidden

Going to example.com/config or example.com/account/login returns 403 Forbidden.
In reality, /config and /account/login should be redirected to index.php but it gives 403.
My directory structure is like this:
/var/www/example
└─/assets
└─/bower_components
└─/node_modules
└─/partials
└─/templates
└─/tests
└─/vendor
└─index.php
This is my Virtual host configuration:
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example
<DirectoryMatch "^/var/www/example/(?!(assets|partials))\w+">
Require all denied
</DirectoryMatch>
<Location />
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</Location>
</VirtualHost>
I want to disallow access to every folder except assets and partials, that's why I added that DirectoryMatch directive.
I use a PHP framework called Slim so I have to add Location and Rewrite directives.
I think Apache thinks my URLs are directories and blocks them. Is there a way to unblock my URLs?
Try adding:
<Directory "/var/www/example">
Order Allow,Deny
Allow From all
</Directory>
above the <DirectoryMatch> container in your vhost config.
Since you're using apache 2.4, then use require all:
<Directory "/var/www/example">
Require all granted
</Directory>
If you're using Apache 2.4 try to add in the end of your VirtualHost:
<Directory /var/www/example>
Options Indexes FollowSymLinks MultiViews
# If you want to enable overrides, you should read:
# http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride
AllowOverride All
Require all granted
Satisfy Any
Order allow,deny
Allow from all
</Directory>

This script is only accessible from localhost

I have a working project with Symfony2.
One of my bundles works well by default but when I activate mod_rewrite I get
This script is only accessible from localhost
This happens only with the routes configured on this bundle, others work fine with mod_rewrite
Here is my vhost config
<VirtualHost *:80>
ServerName my_application.my_domain.net
ServerAdmin xxx#xxx.xxx
DocumentRoot "/var/www/my_application/web"
<Directory /var/www/my_application/web/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from All
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php [QSA,L]
</IfModule>
</Directory>
</VirtualHost>
Where can that come from ?
Update
Example
I'm getting the error when trying to access
my_application.my_domain.net/config/list/produit
If I disable mod_rewrite I can access
my_application.my_domain.net/app.php/config/list/produit
Are you hitting app_dev.php or config.php?
By default, both of those restrict connections from anywhere but localhost and display that exact same message.
Update
After the update, I think the problem may be because you have MultiViews enabled. MultiViews can try to load config.php even if it is just referenced as config. Try removing that and see if it helps improve anything.