I created an Laravel API.
First, it was using HTTP, I needed to change it to use https.
So I created an account on Cloudflare and since then when I go to my API endpoints:
GET: https://www.traapp.tk/api/data/20190809 it gives a 404:
Not Found
The requested URL /api/data/20190809 was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to
use an ErrorDocument to handle the request.
I also have a POST request and that returns a 404 to.
.htacces
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
api.php
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::get('data/{date}', 'MainController#index');
Route::post('route', 'MainController#getAllRoutesOfACertainDay');
MainController
public function index ($date) {
$responseServer = json_decode($this->makeRequest(str_replace('DATE', $date, env('BASE_URL') . env('SCHEDULES'))),true);
return $this->respond($responseServer);
}
I tried solutions like these:
Force Laravel to use HTTPS version
How to implement HTTPS in laravel 5.4
That's a 404 from your Web server not from your laravel. I guess you forgot to change the declared port in your Vhost configuration from 80 to 443.
Cloudflare example:
<VirtualHost *:443>
ServerName.....
First try to enter to GET routes, if you have 403 or 404, the problem is the nginx configuration, look the log, and if the problem is the doesn't find index.html in public_html is the root configuration of your nginx or apache2
Apache 2 has te config in the /etc/apache2/sites-enabled/ and your-domain.conf when you activate ssl in your site the problem can be, that the site generates another conf file, like your-domain.ssl.conf and this file looks like
ServerName domain.com
ServerAlias www.domain.com
ServerAdmin info#domain.com
DocumentRoot /home/admin/web/domain.com/public_html/public <----- here is the change
ScriptAlias /cgi-bin/ /home/admin/web/pdomain.com/cgi-bin/
Alias /vstats/ /home/admin/web/domain.com/stats/
Alias /error/ /home/admin/web/domain.com/document_errors/
#SuexecUserGroup admin admin
CustomLog /var/log/apache2/domains/domain.com.bytes bytes
CustomLog /var/log/apache2/domains/domain.com.log combined
ErrorLog /var/log/apache2/domains/domain.com.error.log
<Directory /home/admin/web/domain.com/public_html>
AllowOverride All
SSLRequireSSL
Options +Includes -Indexes +ExecCGI
php_admin_value open_basedir /home/admin/web/domain.com/public_html:/home/admin/tmp
php_admin_value upload_tmp_dir /home/admin/tmp
php_admin_value session.save_path /home/admin/tmp
</Directory>
<Directory /home/admin/web/domain.com/stats>
AllowOverride All
</Directory>
SSLEngine on
SSLVerifyClient none
SSLCertificateFile /home/admin/conf/web/ssl.domain.com.crt
SSLCertificateKeyFile /home/admin/conf/web/ssl.domain.com.key
SSLCertificateChainFile /home/admin/conf/web/ssl.domain.com.ca
<IfModule mod_ruid2.c>
RMode config
RUidGid admin admin
RGroups www-data
</IfModule>
<IfModule itk.c>
AssignUserID admin admin
</IfModule>
IncludeOptional /home/admin/conf/web/sapache2.domain.com.conf*
Related
I need some help with configuring Symfony on apache2 web server.
My current project category structure is:
var/www/domain.com/public_html
Inside public_html is where my Symfony application is located.
I am stuck at figuring our what I am doing wrong in my either .htaccess or /etc/apache2/sites-available/domain.com.conf files.
I am using symfony/apache-pack. My .htaccess files live inside /public folder as per documentation. Here it is:
DirectoryIndex index.php
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI}::$0 ^(/.+)/(.*)::\2$
RewriteRule .* - [E=BASE:%1]
RewriteCond %{HTTP:Authorization} .+
RewriteRule ^ - [E=HTTP_AUTHORIZATION:%0]
RewriteCond %{ENV:REDIRECT_STATUS} =""
RewriteRule ^index\.php(?:/(.*)|$) %{ENV:BASE}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ %{ENV:BASE}/index.php [L]
</IfModule>
<IfModule !mod_rewrite.c>
<IfModule mod_alias.c>
RedirectMatch 307 ^/$ /index.php/
</IfModule>
</IfModule>
And here is my /etc/apache2/sites-available/domain.com.conf
<VirtualHost *:80>
ServerAdmin someemail#example.com
ServerName mydomain.com
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/mydomain.com/public_html/public>
AllowOverride All
Order allow,deny
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =www.mydomain.com [OR]
RewriteCond %{SERVER_NAME} =mydomain.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I also read this and updated 000-default.conf as follows:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerAlias www.mydomain.com
DocumentRoot /var/www/mydomain.com/public_html/public
<Directory /var/www/domain.com/public_html/public>
Options FollowSymlinks MultiViews
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
Allow from All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<IfModule mod_dir.c>
DirectoryIndex index.php index.pl index.cgi index.html index.xhtml >
</IfModule>
</VirtualHost>
For the moment I am still seeing symfony project folder structure.
I tried:
inside .htaccess changing DirectoryIndex to /public/index.php
inside .conf file changin DocumentRoot to /va/www/domain.com/public_html/public
tried clearing cache
SO far nothings seems to help.
Would be extremely helpful for any advice.
I see that you are editing vhost which begins with
<VirtualHost *:80>......
That mean your website should be reachable by 80 port or in other words by http protocol. But! If in reality you are accessing your website by https protocol then make sure you are editing right Apache2 .conf file.
If the website is reachable by https protocol (especially if you use LetEncrypt), then try locating /etc/apache2/sites-available/....-le-ssl.conf config file (or similar one with corresponding domain title and with ssl prefix or postfix in it's name).
After editing that file do not forget to restart Apache2 webserver with $sudo service apache2 restart and test website again.
Hello I have a WordPress site and I changed the paramlinks from plain to post name. All my posts are showing 404 not found. I tried to check all possible causes but I could not find why it is not working.
My .htaccess is as below:
# 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
Apache mode rewrite is enabled, the command a2enmod rewrite gives:
Module rewrite already enabled
PHP info shows mod_rewrite in Loaded Modules.
My vhost is as following:
<VirtualHost *:80>
ServerName mysite.com
ServerAlias www.mysite.com
ServerAdmin webmaster#mysite.com
DocumentRoot /var/www/mysite/public_html
ErrorLog /var/www/mysite/logs/error.log
CustomLog /var/www/mysite/logs/access.log combined
<Directory "/var/www/mysite/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Any help on this please? Thanks.
I have deployed an application to an apache server and it works fine, well only the homepage. As soon as I try to go to a route I get the Not found error in my request log I see GET /users 404
My virtual host file:
<VirtualHost *:80>
SetEnv ENVPHP acc
ServerName someurlblabla.com
DocumentRoot "/var/www/html/projectname/public"
<Directory "/var/www/html/projectname/public">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
The .htaccess file is just the default laravel one with apache being able to access and read it.
<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>
I'm a bit lost since I don't get any errors in my log and I have no idea what is going on.
what's about this:
<VirtualHost *:80>
SetEnv ENVPHP acc
ServerName someurlblabla.com
DocumentRoot "/var/www/html/projectname/public"
<Directory "/var/www/html/projectname">
Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from All
</Directory>
</VirtualHost>
Probably you don't wanna hear this, but switching to Nginx will solve a lot of these problems , and your site will run faster. That's why Laravel Valet uses Nginx.
i developed a website in laravel but problem is if someone know the name of files he can directly access that files of website which i don't want
JobScholar
app
Exceptions
Http
Mail
Models
Permission.php
Providers -
Role.php
User.php
.env
etc etc
application is working fine but what i want if user type
http://localhost:8080/JobScholar/app/
or
http://localhost:8080/JobScholar/User.php/
he should rediret to home controller or see an error message
my .htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
Options -Indexes
ErrorDocument 403 http://localhost:8080/JobScholar/index
Options +FollowSymLinks
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ /JobScholar/$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>
## Don't listing directory
#Options -Indexes
#
## Follow symbolic links
#
#
## Default handler
#DirectoryIndex index.php
i don't want the user to access any of the file or directory the only directory and files he can see are only those whose routes are defines
Laravel basic flow is that ALL the requests go through index.php file in public folder. So you have to make sure your server points all the request to that folder so index.php can serve and take care of the rest.
Quick fix is to create vHost file(assuming you're not on shared host).
Here's a sample:
<VirtualHost *:80>
ServerName www.site.com
ServerAlias site.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/site_name/public
<Directory /var/www/html/site_name/public>
AllowOverride All
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
On apache server it will go in:
/etc/apache2/sites-available/
Then enable the site a2ensite site_name.conf
Finally point your site to server IP in /etc/hosts like so: 127.0.0.45 site.com
Also be sure to enable mod rewrite using a2enmod rewrite so .htaccess provided by Laravel can make required rewrites to the URL.
Finally restart apache: service apache2 restart
I have Apache 2.4 running on Windows Server 2012 with PHP 5.6.23 on port 8080.
Assume that the domain to my server is "serv1.example.com" I need to run 3 Laravel instances production,staging and dev using the following links
serv1.example.com:8080/production
serv1.example.com:8080/staging
serv1.example.com:8080/dev
I found another SO question which seems to be doing the same thing. But when I tried to do the same thing I get the following error
Forbidden
You don't have permission to access /dev on this server.
Here is what I have done so far. In my httpd-vhosts.conf file I added the following VirtualHost
<VirtualHost *:8080>
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" common
DocumentRoot "C:\www\dev\public"
ServerName serv1.example.com
ServerAlias /dev
<Directory "C:\www\dev">
Options Indexes Includes FollowSymLinks MultiViews
AllowOverride AuthConfig FileInfo Indexes
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Then I changed c:\www\dev\public\.htaccess the code to the following
<IfModule mod_rewrite.c>
#Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /dev/index.php/?$1 [L]
</IfModule>
What did I do wrong here? how can I access each instance using the same domain?
Try This one, in your Apache configure file /etc/apache2/sites-available
<VirtualHost *:8080>
ServerName serv1.example.com
ServerAlias serv1.example.com
DocumentRoot "C:/www/dev/public"
# Rewrites for pretty URLs, better not to rely on .htaccess.
<Directory "C:/www/dev/public">
Options All
AllowOverride All
Require all granted
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
</Directory>
# Log file locations
LogLevel warn
ErrorLog "logs/dev-error.log"
CustomLog "logs/dev-access.log" common
And in your c:\www\dev\public\.htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
I hope this would work. for more information follow these links.Multiple laravelsites on single apache server , multiple web sites in single laravel installation