I have a Laravel 6 app which is working fine locally on redhat apache.
my client setting the domain and must using /abc ater the domain
i.e domain.or/abc
i put my root folder into /var/www/abc/
In config/app.php I have
'url' => 'h t t ps :// domain.or/abc',
In pfi/public/.htaccess I have
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteBase /abc
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
I can access domain.or/abc and the page loads (without styles, images, ...). But all the other links to pages, images, css, js, ... are wrong. For example, they link to
domain.or/css/style.css
instead of linking to
domain.or/PFI/css/style.css
i.e., "PFI" is missing from all the links.
If I go to
domain.or/abc/login
i got 403 error, but if domain.or/login, page load without css,js
and if i open css,js file manually by copy the link to the new tab
i.e domain.or/abc/css/style.css the css dont load, it only show the main page instead of css scripts
in order to fix this issue:
ensure that inside .env file APP_URL=https://domain.or/PFI
ensure the same for config/app.php file 'url' => env('APP_URL', 'https://domain.or/PFI'),
edit your public/index.php you have to change the path of these to line to be consistent with the actual path
$app = require_once __DIR__.'/../path_to_public_folder/bootstrap/app.php';
require __DIR__.'/../path_to_public_folder/vendor/autoload.php';
in .htaccess
<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]
# Redirect http to https
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
<IfModule mod_headers.c>
# Prevent click jacking
Header set X-Frame-Options Deny
Header set X-Frame-Options: SAMEORIGIN
</IfModule>
</IfModule>
I got the answer
The changes i did:(my apps folder is laravel)
create folder on /var/www/ same with ur subfolder domain, sudo mkdir PFI
Create softlink: ln -s /var/www/laravel/public /var/www/PFI
Update httpd.conf
<VirtualHost *:80>
ServerName xxxx
DocumentRoot /var/www/PFI
Redirect permanent / https://xxx/PFI
<Directory /var/www/laravel/public>
AllowOverride All
</Directory>
</VirtualHost>
<VirtualHost _default_:443>
ServerName XXX
DocumentRoot /var/www/PFI
</VirtualHost>
update on my layouts with
and all my css,js change to <href ="css/style.css">
Related
I have the following .htaccess fille:
<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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
#disable directory browsing
Options -Indexes
#PROTECT ENV FILE
<Files .env>
order allow,deny
Deny from all
</Files>
#PROTECT ENV FILE
<Files .htaccess>
order allow,deny
Deny from all
</Files>
But the problem is I get a 404 status code in my production environment when trying to load "getservicedata" from a vue.js component. I think the problem is in the URL because it works when I type in the correct url, but the problem is the app loads the API from wrong URL.
I followed this guide to setup laravel shared hosting: https://laravelarticle.com/deploy-laravel-on-shared-hosting
I'm trying to deploy my Laravel project on Google Cloud VM, it did directing to my index.php file but it supposed to routing to the controller instead of showing the index.php code line.
Here is the result
Then i try to change the .htaccess file like the code below:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
#I'm adding this code
RewriteRule ^(.*)$ public/$1 [L]
# 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]
# Send Requests To Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
And here is the result
After that i remove that line and try to change all the 'AllowOverride None' lines to 'AllowOverride All' inside of apache2.conf file, then remove the lines that prevent .htaccess and .htpasswd files from being viewed by Web clients:
<FilesMatch "^\.ht">
Require all denied
</FilesMatch>
But the result is still same like the first result
And then i'm trying to add this line:
<IfModule dir_module>
DirectoryIndex index.html index.php
</IfModule>
inside of apache2.conf file but then again the result is still same like the first result
I already install Composer inside of the project but it still not working.
Thank you.
P.S: Sorry for my bad English.
I Get Problem With my laravel project
I want to remove index.php in url
like
http://localhost/react/Lara-react/public/admin/home
And i get 404 not found if use this
but if i use
http://localhost/react/Lara-react/public/index.php/admin/home
it's works and
http://localhost:8000/admin/home
^ works to
my .htaccess
<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 have tried
https://laravel.com/docs/5.8/installation#pretty-urls
but not working ...
Someone help
http://localhost/react/Lara-react/public/admin/home
Does not work as the url does not search for index.php as your root path is http://localhost.
When you fire command php artisan serve command, the root of the app becomes
http://localhost/react/Lara-react/index.php hence all the routes are appended to root creating
http://localhost/react/Lara-react/public/index.php/admin/home which make the app work
On production you too define the root path of the project as /var/www/html/react/Lara-react/index.php.
So for development using php artisan serve command is helpful as it creates an simulated environment as production
1). Run common "gedit /etc/apache2/apache2.conf"
Alias /project_name /var/www/html/project_name/public/
<Directory /var/www/html/project_name/public>
AllowOverride All
Order allow,deny
allow from all
</Directory>
2). Add base url in 'project_name/public/.htaccess'
RewriteBase /project_name
3). finally run "service apache2 reastart"
I have installed an SSL certificate for my Laravel website, however when I open it as https://example.com the CSS/JS assets are loaded through HTTP. For example, asset('css/charts.css') amounts to http://example.com/public/css/charts.css and the browser refuses to load it because it's unsafe.
So I followed the answers to several SO questions to force all links to become HTTPS by doing the following:
1) added HTTPS_ONLY=true to .env
2) in app/Providers/AppServiceProvider.php I added the following:
if(env('HTTPS_ONLY')){
$url->forceScheme('https');
}
Inside the service provider's boot method. However, after I do that and try to open https://example.com I get a ERR_TOO_MANY_REDIRECTS error.
This is the vhost file for the domain:
<VirtualHost *:80>
ServerAdmin myemail#gmail.com
ServerName example.com
DocumentRoot /var/www/example.com/public
<Directory /var/www/example.com/public>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
So there is nothing related to HTTPS in there. In example.com/public there is an .htaccess file that I looked at too but its contents seem innocent as well:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^ index.php [L]
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>
Does anyone know what the issue might be and how I can debug this? This is all on Apache, Ubuntu 18.04 server.
asset,url helper will following this environment (.env) value, so change it like this
APP_URL=https://example.com
and run php artisan config:clear
I am using this config for https redirect
the following in appserviceprovider.php
if(config('app.env') === 'production') {
\URL::forceScheme('https');
}
.htaccess in public
Options -MultiViews -Indexes
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]
Recently, i did found something else, If there are assets that are loading on http from external links(like an image on http:://abcd.jpg), then your page will tend to load on http instead of https.
It will get stuck in a loop because the same asset will cause the page to open on http again, causing page to go back on http and redirection will go on.
I'm using Laravel-5 framework and created the following route in the routes/web.php:
Route::get('/test', function () {
return view('test');
});
After navigating to myapp.dev/test I get an Error 404:
Object not found! The requested URL was not found on this server. If you entered the URL manually please check your spelling and try again.
Navigating to myapp.dev/index.php/test works fine. So, looks like rewrite_mod is not working.
I'm using XAMP/Apache and rewrite_module is enabled in httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so
My larvavel's public folder contains a .htaccess file with following content:
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews -Indexes
</IfModule>
RewriteEngine On
#DirectoryIndex index.php
# 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>
The httpd-vhost configuration looks like the following:
<VirtualHost *:80>
ServerAdmin my#mail.com
DocumentRoot "s:/_dev/myapp/public"
ServerName myapp.dev
<Directory "s:/_dev/myapp/public">
Allow from all
Require all granted
#Options Indexes
</Directory>
ErrorLog "logs/myapp.dev-error.log"
CustomLog "logs/myapp.dev-access.log" common
</VirtualHost>
Any ideas what I missed?
Thanks
I can not see any issues with our code however it could be a browser issue.
Have a look at this article which goes through the changes to browsers that cause issues with .dev domains.
https://medium.engineering/use-a-dev-domain-not-anymore-95219778e6fd