laravel time out error - apache

i have a project running in ubuntu-apache2 with laravel 5.3. The problem is that laravel works on some users but on others it doesn't. When you make the url request the page stays on hold, and you canĀ“t see anything. It's strange because i have users that are using the app normally.
I saw the apache log and i can see the 302 request but not the answer. I change in site-avaible conf the document root to the root path and a I can see the indexes, so i think the problem is in the .htacces file, although I have not made any changes. This is my .conf ->
ServerAdmin serveradmin#serveradmin.com
ServerName localhost
ServerAlias theurlofmypage
DocumentRoot /var/www/html/extranet/public
<Directory "/var/www/html/extranet/public">
AllowOverride All
Options FollowSymLinks Indexes
Order allow,deny
Allow from all
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
And this is the .htacces file:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Can anyone help me??

A 302 is most likely a Laravel response, not an apache thing seeing you redirect with a 301 as far as I can tell.
I had an instance where this drove me nuts too. It happend because I had putten a redirect() somewhere in the code and some requests triggerd it. It redirected back to itself to a part with a wrong namespace which didn't fly.
All I can recommend is temporarily disable middleware and Requests (validation). If that doesn't work try to find all your abort's and redirect()'s.

Related

request matching RewriteRule returns permission denied

I am experiencing a bizarre apache error. I'd like to rewrite all requests from /api/media/fi/le/path.jpg to /media/fi/le/path.jpg
This are rewrite rules setup in virtual host:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /api/v1/* /src/api/v1/index.php [L]
RewriteRule /api/media/(.*) /media/$1 [L]
If I point the browser to /media/fi/le/path.jpg, the image gets server successfully. If I go to /api/media/fi/le/path.jpg it complains that I do not have permission to access the resource. I must have permission, because I can access the file if no rewrites are done. How should I rewrite the last RewriteRule so that it would serve the images?
I added logging directive LogLevel alert rewrite:trace6 to see what the apache is doing under the covers. This are the results:
init rewrite engine with requested uri /api/media/32/ee/0e60731bcb220c7c7b.jpg
applying pattern '/api/v1/*' to uri '/api/media/32/ee/0e60731bcb220c7c7b.jpg'
applying pattern '/api/media/(.*)' to uri '/api/media/32/ee/0e60731bcb220c7c7b.jpg'
rewrite '/api/media/32/ee/0e60731bcb220c7c7b.jpg' -> '/media/32/ee/0e60731bcb220c7c7b.jpg'
local path result: /media/32/ee/0e60731bcb220c7c7b.jpg
go-ahead with /media/32/ee/0e60731bcb220c7c7b.jpg [OK]
I can visit the url mydomain.com/media/32/ee/0e60731bcb220c7c7b.jpg manually and the image gets server with no problem. What am I missing?
Complete .conf file for virtual host:
<IfModule mod_ssl.c>
<VirtualHost *:443>
DocumentRoot /home/user/project/src
ServerName project.com
ErrorLog logs/project-error_log
CustomLog logs/project-access_log common
DirectoryIndex index.php
<Directory /home/user/project/src>
Options -Indexes +FollowSymLinks
AllowOverride None
Require all granted
</Directory>
LogLevel alert rewrite:trace6
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule /api/v1/* /api/v1/index.php
RewriteRule /api/media/(.*) /media/$1 [L]
SSLCertificateFile /etc/letsencrypt/live/project.com/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/project.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateChainFile /etc/letsencrypt/live/project.com/chain.pem
</VirtualHost>
</IfModule>
There is weird behaviour with rewrite engine.
RewriteRule /api/media/(.*) /media/$1 [L]
Will always return forbidden. After mv media images and changing the above directive to RewriteRule /api/media/(.*) /images/$1 [L], permission error is gone.

Deploy a CakePHP website fails. An apache2 config issue?

I'm deploying a CakePHP (1.3.2) website for the first time. It was hosted on an older server. I received the project as a zip file. I managed to install it on my localhost and made the changes I needed.
Now I have to deploy it to a new server, but I face a problem.
The routing doesn't seem to work. I guess it's an .htaccess issue.
When I access the root folder, it redirects me to /login but then I have a 404:
The requested URL /login was not found on this server.
My 3 main .htaccess files (/, /app and /app/webroot) are the following. (CakePHP is installed at the root of my virtual host)
Root
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
/app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/app/webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
mod_rewrite seems to be activated on my server as it responds with this when I try to add it:
Module rewrite already enabled
But when I try something simple like that on top of my root .htaccess, it doesn't do anything:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^.*$ test.php
</IfModule>
(I was following this guide: https://docs.bolt.cm/howto/making-sure-htaccess-works)
Among a lot of things, I also tried to add that to all my .htaccess:
Option Indexes
But it didn't help.
Here is my website conf file too:
<VirtualHost xx.x.xx.xx:80>
ServerAdmin xxx#company.com
ServerName xxx.company.com
DocumentRoot /var/www/xxx.company.com
DirectoryIndex index.html index.php
php_value error_log "/var/log/apache2/xxx.company.com-phperror.log"
php_flag register_globals off
<Directory "/var/www/xxx.company.com">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/xxx.company.com-error.log
CustomLog /var/log/apache2/xxx.company.com-access.log common
</VirtualHost>
(I added the Directory section that was not here in the first place)
After a lot of trials, I still haven't found anything that seems to solve my problem.
As I'm definitely not used to work on server side, It might be a simple thing that you will immediately spot. I hope so.
Thanks
I finally got it to work. Here are the two mistakes I made:
I had my document root set cake's root folder instead of the webroot folder. I added /app/webroot after DocumentRoot /var/www/xxx.company.com in my .conf file.
Also, I was using apache's reload function, which is actually not properly reloading. Using service apache2 restart instead does the job.

Apache mod_rewrite not happening on localhost

I can't seem to get my head around this. I just pulled down my website files from my server to work on them offline. However, my rewrite conditions are no longer working as expected.
I've been googleing for the last 3 hours and keep coming to these solutions:
put garbage in the .htaccess file to make sure it's being read. I did that and got a 500 error so it is.
Make sure mod_rewrite is enabled, and I make sure it was listed in php_info(). That's not the problem.
Other than that, I can't figure this thing out.
Here's my .htaccess. All I want to do is remove index.php from my URLs:
# Rewrite url no index.php
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
RewriteRule . index.php
Here's my virtual host config at the moment:
<VirtualHost *:80>
ServerAdmin xxxx#gmail.com
DocumentRoot "c:/wamp/www/myapp/public_html/"
<Directory "c:/wamp/www/myapp/public_html/">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ServerName myapp.local
ErrorLog "logs/myapp.local"
CustomLog "logs/myapp.local" common
</VirtualHost>
I'd also like to make it known that rewrite rules seem to work a bit when they're in the virtual host config. So something like this:
<VirtualHost *:80>
ServerAdmin xxx#gmail.com
DocumentRoot "c:/wamp/www/myapp/public_html/"
<Directory "c:/wamp/www/myapp/public_html/">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# ...other settings...
</Directory>
ServerName myapp.local
ErrorLog "logs/myapp.local"
CustomLog "logs/myapp.local" common
</VirtualHost>
I had other problems with this though since I have nested applications (one's at / and the other at /app2/). I also seemed to have problems with the !-f condition being ignored and it would rewrite the URLs of my images and css.
Does anyone have any ideas on how to fix this? Thanks in advance!
You should use your code like this to remove index.php from the URL.
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /index\.php(.*)\ [NC]
RewriteRule ^ %1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php [L,QSA]
And then in your head section of your html add this to fix CSS problem.
<base href="http://myapp.local" />

redirecting domain only works for /, no subdirectories

I have just spent a good 2 hours on this problem and really can't find a solution here. I have a server hosting several websites, but for some reason one of them is behaving differently from the others: the non-www is redirecting to the www domain only for /.
I have looked in virtual hosts and .htaccess of that domain, but whatever I do, I can only get the / to correctly display. All other URLs return a 404 page (and not even the nice one I designed for the website - the server's default 404 page).
Here is my virtual hosts config:
<VirtualHost *:80>
DocumentRoot /home/frsechet/francoissechet
ServerName francoissechet.com
<Directory /home/frsechet/francoissechet>
allow from all
Options +Indexes
</Directory>
ServerAlias www.francoissechet.com
</VirtualHost>
And here is my .htaccess (but I've tried a lot of other solutions too, none of them worked, and at most it broke the rest of the website)
RewriteCond %{HTTP_HOST} ^francoissechet.com$
RewriteRule (.*) http://www.francoissechet.com/$1 [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If any one of you has a clue where I could look next, I would greatly appreciate!
Thanks!
Edit - added the wordpress part of the .htaccess.

mod_rewrite: multiple domains on one server, mod_rewrite refuses to work on one

I have a server that serves several domains from a single IP address using Apache's Virtual Host shenanigans. Three of the sites are required to redirect to www if it's omitted from the URL.
I have the following rule in the .htaccess file of each domain:
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
This works for two of the three, but the third completely fails to comply. I know that the .htaccess is being hit because the framework requires all hits to be routed through index.php... and that is happening correctly. So, it's not permissions, and the .htaccess is identical (more or less) on each domain. I even looked into caching (even though that doesn't make any sense... desperation gives way to insanity!)
Please help me if you have any clue what is going on.
As requested, here's the complete vhost config, and .htaccess file...
vhost configuration:
<VirtualHost *:80>
ServerAdmin me#gmail.com
DocumentRoot /var/www/example.com
ServerName www.example.com
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/example.com>
Options FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
LogLevel warn
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
.htaccess file:
# BEGIN example.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=40]
####################################################
# If requested URL-path plus ".php" exists as a file
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
# Rewrite to append ".php" to extensionless URL-path
RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]
####################################################
# redirect to RoutingHandler
RewriteRule ^.*$ /index.php [NC,L]
</IfModule>
# END example.com
Bear in mind, there are two other domains set up in an identical manner... and they both work with zero issues.
I know this is an old question, but google brought me here while looking for answers on the same problem.
After searching through apache's documentation I found:
AllowOverride Directive
When this directive is set to None, then .htaccess files are completely ignored. In this case, the server will not even attempt to read .htaccess files in the filesystem.
So I changed "AllowOverride None" to "AllowOverride All" in the <Directory /var/www/example.com> section and it worked.