I've seen a lot of similiar topics and I tried all of them and previously it worked, every time different one, but now nothing...
So I want to remove /public from my URL and it works for laravel-public_html but not for build version
I'm using VPS (CentOS 7 with CWP 7)
My structure is like this:
/home/admin/
-laravel
-public_html (public folder for laravel)
-laravel_build
-build (public folder for laravel_build)
and with that I have build.mypage.com and www.mypage.com
httpd.conf
...
ServerRoot "/usr/local/apache"
...
DocumentRoot "/home/admin/public_html"
<Directory "/home/admin/public_html">
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
index.php (public_html)
require __DIR__.'/../laravel/bootstrap/autoload.php';
$app = require_once __DIR__.'/../laravel/bootstrap/app.php';
index.php (build)
require __DIR__.'/../laravel_build/bootstrap/autoload.php';
$app = require_once __DIR__.'/../laravel_build/bootstrap/app.php';
Should I add something in .htaccess , and if yes, where do I need to put that .htaccess?
Edit: I already have .htaccess in public folders for laravel routes(mod _rewrite)
Assuming you are using something like MAMP or XAMP, if possible do not add anything in httpd.comf, instead you could do something
like below in your httpd-vhosts.conf.
You may have to look for a directory in your environment where to put the virtual host file (and sometime you have to uncomment that path in your httpd.conf)
Example of entry in httpd-vhosts.conf:
<VirtualHost *:80>
ServerAdmin yourEmail#domain.com
DocumentRoot "/home/admin/laravel/public_html"
ServerName MySite1.com
ServerAlias MySite1.com
ErrorLog "logs/MySite1_com-error.log"
CustomLog "logs/MySite1_com_access.log" common
php_value error_log "logs/php_error.log"
</VirtualHost>
<VirtualHost *:80>
ServerAdmin yourEmail#domain.com
DocumentRoot "/home/admin/build"
ServerName subdomain.MySite1.com
ServerAlias subdomain.MySite1.com
ErrorLog "logs/subdoamain-MySite1-error.log"
CustomLog "logs/subdoamain-MySite1-error.log" common
php_value error_log "logs/php_error.log"
</VirtualHost>
Add two entries for both the apps.
I feel so stupid now, the problem was actually that I did not Hard Reset and Clear Cache in Google Chrome so it loaded previous configuration
For others that have similiar problem, solutions to try:
1.Create vHosts for subdomain and domain
2.Put .htaccess in public folder, not laravel folder
My current .htaccess is as follows(both public_html and build):
<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]
</IfModule>
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
</IfModule>
Related
I have an admin panel that written on laravel 8.
The root directory of the laravel is projectfolder, not public.
but both directory has .htaccess. I'm running this on a VPS with Ubuntu 20.04, Apache/2.4.41 and php7.4.3 (have installed all the necessary extensions) and installed ssl using certbot.
.htaccess contents from the root project folder
<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]
# cors
Header set Access-Control-Allow-Origin "*"
<Files .env>
Order allow,deny
Deny from all
.htaccess contents from the public folder
<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]
# cors
Header set Access-Control-Allow-Origin "*"
My apache admin.example.com.conf contents
<VirtualHost *:80>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName admin.example.com
ServerAlias admin.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/admin.example.com
<Directory /var/www/html/admin.example.com/ >
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
RewriteEngine on
RewriteCond %{SERVER_NAME} =admin.example.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet
My admin.example.com-le-ssl.conf contents
<IfModule mod_ssl.c>
<VirtualHost *:443>
# The ServerName directive sets the request scheme, hostname and port that
# the server uses to identify itself. This is used when creating
# redirection URLs. In the context of virtual hosts, the ServerName
# specifies what hostname must appear in the request's Host: header to
# match this virtual host. For the default virtual host (this file) this
# value is not decisive as it is used as a last resort host regardless.
# However, you must set it for any further virtual host explicitly.
ServerName admin.example.com
ServerAlias admin.example.com
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/admin.example.com
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
# For most configuration files from conf-available/, which are
# enabled or disabled at a global level, it is possible to
# include a line for only one particular virtual host. For example the
# following line enables the CGI configuration for this host only
# after it has been globally disabled with "a2disconf".
#Include conf-available/serve-cgi-bin.conf
SSLCertificateFile /etc/letsencrypt/live/admin.example.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/admin.example.com/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
Tried the followings
Added AllowOverride All
Enabled rewrite module along with expires
Changed <Directory / > to AllowOverride All in /etc/apache2/apache2.conf
Set APP_DEBUG=false in .env
Provided user permission www-data for the .htaccess file.
The front page loads fine. But when I click the Ready ? then Start button, 404 appears. Can anyone provide a solution for this as am a complete beginner?
Console error messages
I made a virtual host on the remote server and it works, but I would like to include the name of the app in the url address...
example: 10.10.20.30 - work, the homepage of the app opens, but 10.10.20.30/e-lab don't work...
These are my files for a virtual host:
httpd-vhost.conf
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/e-lab/public"
ServerName e-lab.test
<Directory "C:/xampp/htdocs/e-lab/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
Require all granted
</Directory>
hosts
127.0.0.1 localhost
127.0.0.1 e-lab.test
and htaccess
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ / [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
Thanks! ;)
I solved the problem ... In the localhost links works ok, example: <a href=/login> , but over the remote server this slash line deletes the folder name (name of aplication), so i put it all links {{url('something')}} and now it's ok ... thanks anyway ;) –
I'm trying to install Laravel on Wamp server and I'm getting this error:
{"status":"Not Found","error":true,"error_code":"missing_route","message":"Route not found.","data":[]}
Been searching for a while now and can't figure out what it is. I checked and triple checked if I added corectly my project in hosts file, if virtual host is set properly, also if rewrite module is activated and if .htaccess file in the public folder is as it should.
Hosts File:
127.0.0.1 app.my-site.com
Vhosts
<VirtualHost *:80>
ServerAdmin webmaster#my-site.com
DocumentRoot "C:/wamp/www/my-site/public"
ServerName app.my-site.com
<Directory "C:/wamp/www/my-site/public">
AllowOverride All
Order allow,deny
Allow from all
</Directory>
ErrorLog "logs/my-site-error.log"
CustomLog "logs/my-site-access.log" common
</VirtualHost>
.htaccess in public folder
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
Options +FollowSymLinks
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]
</IfModule>
Can anybody suggest what could be wrong?
I have a frontend app at /var/www/html/app and the API for that app is at /var/www/html/api. There is a virtual host set up for /var/www/html/app, with the name example.com. Now, I want it so what when a user visits example.com/api, it will redirect all requests to /var/www/html/api.
Example:
User enters http://example.com/api/some/call into their browser - instead of the server looking for /var/www/html/app/api/some/call, it will look for /var/www/html/api/some/call.
What is the best way to get this done? I tried using symbolic links which works for just /api, but not for variable routes after /api. I am thinking I can get it working with mod rewrite, but I am not that familiar with it.
UPDATE
Here is the config for example.com in /etc/apache2/sites-available:
<VirtualHost *:80>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html/app
ServerName example.com
ServerAlias www.example.com
<Directory /var/www/html/app>
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>
Here in the .htaccess file in /var/www/html/app (and the same one at /var/www/html/api):
<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]
</IfModule>
Below you will find my current vHost entry that I am using for a site that I currently have under development. This vHost entry works fine when I have it on my local machine, but when I push my code to my staging server that is running this same vHost record I receive a 500 Internal Server error.
The machine I'm running this vHost on is running Apache 2.2.9 (Debian).
<VirtualHost 206.217.196.61:80>
SuExecUserGroup 13labs 13labs
ServerAdmin aellis#1three.com
ServerName admin.13labs.net
ServerAlias admin.13labs.net
DirectoryIndex index.php
DocumentRoot /var/www/13labs.net/html/admin/
ErrorLog /var/www/13labs.net/logs/error.log
# Hide .svn Directories
<DirectoryMatch "\.svn">
Order deny,allow
deny from all
</DirectoryMatch>
# FastCGI
Alias /fcgi-bin/ /var/www/13labs.net/fcgi-bin/
AddHandler php-fastcgi .php
AddType application/x-httpd-php .php
Action php-fastcgi /fcgi-bin/admin-php.fcgi
<Directory /var/www/13labs.net/fcgi-bin/>
SetHandler fcgid-script
AllowOverride None
Options -Indexes +ExecCGI -FollowSymlinks -SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
<Directory /var/www/13labs.net/html/admin/>
AllowOverride None
Options -Indexes -FollowSymlinks -SymLinksIfOwnerMatch
FileETag All
</Directory>
# Rewrite Logic
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !\.(gif|jpe?g|png|js|css|swf|php|ico|txt|pdf)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/(.+)$ /index.php/$1 [PT,QSA,L]
Thanks for any help that you can provide.
Best regards,
Andrew
After many trial and errors I have found that the working RewriteRule needs to be the following:
RewriteRule ^.*$ /index.php$1 [PT,QSA,L]
Then in PHP I need to be using $_SERVER['REQUEST_URI'] instead of $_SERVER['PATH_INFO'] to make sure my PHP script see the passed in URI.