Laravel sends the server on 10 redirects? - apache

Getting error message:
[Sun Jun 02 12:43:33.579095 2013] [core:error] [pid 4964:tid 808] [client 127.0.0.1:56964] AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a
When trying to use laravel to do routing. My routes are as follows:
Route::get('/', 'HomeController#showWelcome');
Route::get('history', 'HistoryController#showHistory');
And my .htaccess:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And my alias:
Alias /wunhopkuendo/ "c:/wamp/www/wunhopkuendo/public/"
<Directory "c:/wamp/www/wunhopkuendo/public/">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>

I had this problem as well, and I solved it with the following line on the .htaccess file:
RewriteBase /

If you are using Laravel in a subfolder, you need to follow these steps:
Assuming that you use WAMP with the default installation directory (i.e. c:\wamp)
Insert the RewriteBase line in your .htaccess file with the subfolder of your Laravel instalation.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /subfolder
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
<IfModule>
Set the application URL on file c:\wamp\www\subfolder\config\app.php
'url' => 'http://localhost/subfolder',
Create a configuration file on alias directory c:\wamp\alias\subfolder.conf with this content:
Alias /subfolder "c:/wamp/www/testando/public"
<Directory "c:/wamp/www/subfolder/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Allow from all
</Directory>

Check if your public folder is setup properly

In my case the .htaccess in public folder was missing because of that it was throwing this redirect error. Make sure that your "public/.htaccess" file is available. Hope its helps.

Related

Apache2 loop redirect on a App installed in a subfolder

I try to install my Symfony 4 app on a subfolder (on a "dev server") but I have some problems with the apache2 configuration (I'm complete noob with apache)
So here is my structure
My app is installed in /var/www/html/rapp/
I have an apache config file in /etc/apache2/sites-enabled/rapp.confwith the following content
<VirtualHost *:80>
DocumentRoot /var/www/html/rapp/public
<Directory /var/www/html/rapp/public>
AllowOverride All
Order Allow,Deny
Allow from All
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /rapp/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L,NC]
</IfModule>
</Directory>
# uncomment the following lines if you install assets as symlinks
# or run into problems when compiling LESS/Sass/CoffeeScript assets
# <Directory /var/www/project>
# Options FollowSymlinks
# </Directory>
# optionally disable the RewriteEngine for the asset directories
# which will allow apache to simply reply with a 404 when files are
# not found instead of passing the request into the full symfony stack
<Directory /var/www/html/rapp/public/bundles>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
<Directory /var/www/html/rapp/public/build>
<IfModule mod_rewrite.c>
RewriteEngine Off
</IfModule>
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
On my app root folder (so /var/www/html/rapp/), I have an .htaccess file with the following content to redirect http://xxx.xxx.xxx.xxx/rapp/ url to my app
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /rapp/
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
I have no .htaccess in /var/www/html/rapp/public because it must be handle by the Directory tag in my apache .conf file (I think)
With all that config I have these errors in apache error.log
Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
r->uri = /rapp/public/public/public/public/public/public/public/public/public/public/
redirected from r->uri = /rapp/public/public/public/public/public/public/public/public/public/
redirected from r->uri = /rapp/public/public/public/public/public/public/public/public/
redirected from r->uri = /rapp/public/public/public/public/public/public/public/
redirected from r->uri = /rapp/public/public/public/public/public/public/
redirected from r->uri = /rapp/public/public/public/public/public/
redirected from r->uri = /rapp/public/public/public/public/
redirected from r->uri = /rapp/public/public/public/
redirected from r->uri = /rapp/public/public/
redirected from r->uri = /rapp/public/
redirected from r->uri = /rapp/
I don't really understand why it search dor that much of public subfolder.
And finally, what I would like to do is:
When I go to http://xxx.xxx.xxx.xxx/rapp/ it redirects me on my app in /var/www/html/rapp/.
So I want to have the subfolder where the app is installed, but not the public/index.php or public/ part in the URL.
The problem is that your rule's pattern (.*) also matches the destination path /public/$1 and rewrites the destination to itself in loop mode. You need to exclude the destination path in your RewriteRule to avoid the rewrite loop error.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /rapp/
RewriteRule ^((?!public/).*)$ public/$1 [L]
</IfModule>
Or you can also use a Condition to exclude the destination path
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /rapp/
RewriteRule %{REQUEST_URI} !/public
RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

Too many redirects error and browser shows

With Reference htaccess RewriteRule redirecting to parent directory?
Thank you Francesco Casula, your answer was very helpful, application now redirects from one document root to other. I am facing infinite redirects issue.
I have following repositories with different version.
/var/www/portal/version/1.1.1/public/ binded with (api.somedomain.com)
/var/www/portal/version/1.1.2/public/
/var/www/portal/version/1.1.3/public/
/var/www/portal/version/1.1.4/public/
I want to execute api in following order (by version)
api.somedomain.com/qr ---> /var/www/portal/version/1.1.1/public/
api.somedomain.com/v2/qr ---> /var/www/portal/version/1.1.2/public/
api.somedomain.com/v3/qr ---> /var/www/portal/version/1.1.3/public/
api.somedomain.com/v4/qr ---> /var/www/portal/version/1.1.4/public/
My httpd.conf is
AliasMatch ^/v2/(.*)$ "/var/www/portal/version/1.1.2/public/"
<Directory "/var/www/portal/version/1.1.2/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
.
.
AliasMatch ^/v4/(.*)$ "/var/www/portal/version/1.1.4/public/"
<Directory "/var/www/portal/version/1.1.4/public">
Options Indexes FollowSymLinks MultiViews
AllowOverride all
Order allow,deny
Allow from all
</Directory>
and .htaccess in /var/www/portal/version/1.1.4/public/ contains
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_URI} ^/v2/(.*)$
RewriteRule ^(.*)$ v2/index.php [QSA,L] # p2 is the symlink name!
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
When I hit https://api.somedomain.com/v2/invitebysms
I get too many redirects error and browser shows
https://api.somedomain.com/v2/invitebysms/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/index.php/
I think what you're going for is the following:
Alias /v4/ /var/www/portal/version/1.1.4/public/
<Directory /var/www/portal/version/1.1.4/public/>
Require all granted
FallbackResource /v4/index.php
</Directory>
In as far as I understand what you're trying to accomplish, the above, in your server config (delete the .htaccess file entirely) will do what you want. (Repeat for v2, v3, and so on.)
I am assuming here that you're running at least 2.2.16 or later, and preferably 2.4. If not, let me know, and we'll try again.

Rewriterule alias matching directory name?

Is it possible to create a rule that matches an existing directory?
As in the following example:
RewriteRule ^foo$ foo.php
Considering that is also a folder called "foo", Apache tries to open the directory instead of parsing the rule. Is it possible that the rule precedes the directory?
thank you
Testing with the following config:
Options +FollowSymlinks
Options -MultiViews
RewriteEngine on
AddDefaultCharset iso-8859-1
RewriteRule ^foo$ foo.php
And receiving the following error from apache: [Fri Mar 07 15:06:34 2014] [alert] [client 127.0.0.1] C:/htdocs/www.acasa.org.br.v2/.htaccess: Option MultiViews not allowed here
You need to use -MultiViews for it to ignore the folder.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^foo/?$ foo.php [L]
You can toggle DirectorySlash on and off with:
DirectorySlash Off
However the suggested way to resolve your images issue is by using:
<base href="http://www.domain.com/" />

default cakePhp .htaccess file does not work with redirection

I just installed an Ubuntu web server with apache2. I upload a CakePHP project. I also activated rewrite_mod.
# sudo a2enmod rewrite
When navigating to www.mysite.ch/pierre/contacts it states:
Not found
The requested URL /contacts was not found on this server.
In my local webserver, it works and I can see the contact page
If I remove my project and add a file phpinfo.php with the function phpinfo(), it show information about the server configuration and I do not have a message "not found"
I suspect that my redirection does not work.
What do you think?
Which are the basic step to make an Apache2 server working with an .htaccess file?
Here are is my .htaccess file (it is the default cakephp file, I have not changed it)
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Here is my httpd_conf file
<Directory /var/www/vhosts/metauxch/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,Deny
allow from All
</Directory>
Alias /pierre /var/www/vhosts/pierre/httpdoc
<Directory /var/www/vhosts/pierre/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order Allow,Deny
allow from All
</Directory>
Do you have some idea?
Change AllowOverride None to AllowOverride All in httpd_conf file
Enable mode rewrite,
sudo a2enmod rewrite
restart apache,
sudo /etc/init.d/apache2 restart
I am sorry, I forgetten to write but I did it
sudo a2enmod rewrite
sudo servive apache2 restart
This is done.
I also change this AllowOverride All
The probleme, now is when I enter
http://eflumpc38.epfl.ch/pierre/contacts
It state that te controller pierre (CakePHP) is missing. While pierre is the root and contacts is the controller.
Second point, when I clink on the Contact (root/contacts/)
I have a such URL
http://eflumpc38.epfl.ch/vhosts/pierre/httpdoc/contacts
instead of
http://eflumpc38.epfl.ch/pierre/contacts
Does some thing is wrong here
Alias /pierre /var/www/vhosts/pierre/httpdoc
<Directory /var/www/vhosts/pierre/httpdoc>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order Allow,Deny
allow from All
</Directory>
When I upload the same CakePHP projet on my usual provider, I do not have this issue.
Thank
try this solution.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /app/webroot/ [L]
RewriteRule (.*) /app/webroot/$1 [L]
</IfModule>
CakePHP app directory (will be copied to the top directory of your application by bake):
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ /webroot/ [L]
RewriteRule (.*) /webroot/$1 [L]
</IfModule>
CakePHP webroot directory (will be copied to your application’s web root by bake):
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php [QSA,L]
</IfModule>

Wordpress Options FollowSymLinks error

I have a website setup in my /httpdocs directory with it's own htaccess and I have a wordpress blog within /httpdocs/blog, using the standard wordpress htaccess
I keep seeing the following error in my apache error log:
[error] [client #.#.#.#] Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/vhosts/somedomain.com/httpdocs/blog/index.pl
I added "Options +FollowSymLinks" as this seems to have fixed the problem for others (but not me)
The main .htaccess is as follows:
The Wordpress .htaccess is:
Options +FollowSymLinks
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /blog/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /blog/index.php [L]
</IfModule>
# END WordPres
I am also wondering why the error is reported as "index.pl" since there are no perl scripts in /blog. So, after some searching, I found an httpd.include file (plesk generated) in the /var/www/vhosts/somedomain/conf/ which contains some perl handler stuff:
SetHandler perl-script
PerlHandler ModPerl::Registry
Options ExecCGI
allow from all
PerlSendHeader On
If I remove perl support via Plesk, thus removing the above block of code, then I don't get errors anymore.
The obvious answer would be to disable perl as I don't need it, however there must be a way to fix this error without having to do that?
add to .htaccess
Options FollowSymLinks
all done :)