I'd like to serve my Laravel application in a subfolder in my domain mydomain.com/project1. How should I write my routes.php? I'm using something like this:
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', ['middleware' => 'auth','uses' => 'HomeController#index'])->name('home');
// Authentication
Route::get('auth/login', 'Auth\AuthController#getLogin');
Route::post('auth/login', 'Auth\AuthController#authenticate');
Route::get('auth/logout', 'Auth\AuthController#getLogout');
// AdministraĆ§Ć£o
Route::group(['prefix' => 'administracao', 'middleware' => 'auth'], function() {
Route::resource('filiais', 'FiliaisController');
Route::resource('precos', 'PrecosController');
Route::resource('funcionarios', 'FuncionariosController');
Route::resource('cargos', 'CargosController');
Route::resource('vendedores', 'VendedoresController');
});
// Comercial
Route::group(['prefix' => 'comercial', 'middleware' => 'auth'], function() {
Route::resource('clientes', 'ClientesController');
Route::resource('fichas', 'FichasController');
});
// Operacional
Route::group(['prefix' => 'operacional', 'middleware' => 'auth'], function() {
Route::resource('agenda', 'AgendaController');
Route::resource('os', 'OsController');
Route::resource('ambientes', 'AmbientesController');
Route::resource('processos', 'ProcessosController');
Route::get('relatorios', 'RelatoriosController#index');
Route::get('relatorios/word/{os}', 'RelatoriosController#word');
Route::get('relatorios/excel/{os}', 'RelatoriosController#excel');
Route::get('relatorios/create', 'RelatoriosController#create');
Route::group(['prefix' => 'processo', 'middleware' => 'auth'], function() {
Route::get('create', 'ProcessoController#create');
Route::get('index', 'ProcessoController#index');
Route::post('{os}/parse', 'ProcessoController#parse');
Route::get('{os}', 'ProcessoController#principal');
Route::match(['get', 'post'], '{os}/detalhe', 'ProcessoController#detalhe');
Route::get('{os}/duplicidades', 'ProcessoController#duplicidades');
Route::get('{os}/restantes', 'ProcessoController#restantes');
Route::match(['get', 'post'], '{os}/auditoria', 'ProcessoController#auditoria');
Route::match(['get', 'post'], '{os}/operadores', 'ProcessoController#operadores');
Route::match(['get', 'post'], '{os}/divergencia', 'ProcessoController#divergencia');
Route::match(['get', 'post'], '{os}/finalizar', 'ProcessoController#finalizar');
Route::get('{os}/excluir/{setor}', 'ProcessoController#destroy');
});
});
And I get NotFoundHttpException in RouteCollection for any url. I also tried to add the route prefix Route::group(['prefix' => 'subfolder'], function () {...} but it still doesn't recognize
EDIT
I didn't edit my htaccess and it's:
<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]
</IfModule>
Go to index.php and change
#From this
require __DIR__.'/../bootstrap/autoload.php';
#To this
require __DIR__.'/../[framework-folder]/bootstrap/autoload.php';
#From this
$app = require_once __DIR__.'/../bootstrap/app.php';
#To this
$app = require_once __DIR__.'/../[framework-folder]/pulcro/bootstrap/app.php'
.htacces
RewriteEngine On
# Redirect Trailing Slashes...
RewriteCond %{REQUEST_URI} !^
RewriteRule ^(.*)$ /$1 [L]
Related
I have the project with the following routes:
Route::namespace('Admin')->prefix('admin')->group(function () {
Route::group(['middleware' => 'auth:admin'], function () {
// this is working on my local machine but it's skipped on server which is a subdomain.
Route::get('/', 'DashboardController#index')->name('admin.dashboard');
// other routes here. all of them working fine
Route::resource('pages', 'PageController')->except(['show']);
});
});
Route::get('/', 'HomeController#index'); // this is working fine
On my local machine when I open app.test/admin everything work as expected. I can see my login page if I'm not logged in or the dashboard view if I am.
On the server, which is a subdomain, if I open subdomain.app.com/admin I see nothing. The server response is 200 without any error. All subsequent routes like admin/pages work fine.
The document root in apache is set to the root of the project, not inside public folder. I use the following .htaccess file in the root directory.
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ public/$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ server.php
</IfModule>
I expect the /admin route to show the dashboard view but I get a blank page. Where can be the issues when there is no error?
Does building your Routes list like this help at all?
Route::group(
[
'domain' => '{account}.app.test',
'prefix' => 'admin', // This is the URL prefix
'as' => 'admin.', // This gets pre-pended to the route names.
'middleware' => 'auth:admin',
'namespace' => 'Admin'
],
function () {
Route::get('/', 'DashboardController#index')->name('dashboard'); // with 'as' property, this becomes 'admin.dashboard'
Route::resource('pages', 'PageController')->except(['show']);
}
);
You can do this by setting your admin and user domains in your .env file and then using Route::domain like so:
Route::domain(env('APP_ADMIN_URL'))->group(function() {
Route::get('/', 'AdminController#index');
});
Route::domain(env('APP_USER_URL'))->group(function() {
Route::get('/', 'UserController#index');
});
No need to touch your htaccess other than to make sure that your both of your domains route to your laravel public directory
I found the answer ;)
The problem was that I had a folder called admin in my public folder wich was the same as the route I was trying to access. Renaming that folder to a random name fixed my /admin route.
I downloaded CMS project from github, Laravel version 5.2. I installed the composer in the folder and change the database info in .env file and the project working fine.
But only the home route is working, the rest of the routes giving me "Opps no page avaible"
The blades files are fine only the routes not working!
<?php
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::auth();
Route::get('/home', 'HomeController#index');
Route::get('/post/{id}', ['as' => 'home.post', 'uses' => 'AdminPostsController#post']);
Route::group(['middleware' => 'admin'], function () {
Route::get('/admin', ['as' => 'admin.index', function () {
return view('admin.index');
}]);
Route::resource('admin/users', 'AdminUsersController');
Route::resource('admin/posts', 'AdminPostsController');
Route::resource('admin/categories', 'AdminCategoriesController');
Route::resource('admin/medias', 'AdminMediasController');
Route::resource('admin/comments', 'PostCommentsController');
Route::resource('admin/comment/replies', 'CommentRepliesController');
});
Route::group(['middleware' => 'auth'], function () {
Route::post('comment/reply', 'CommentRepliesController#createReply');
});
and here is .htaccess 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>
Because this route is defined before your resource route, your routes will not match the resource action resulting into "Opps! no page available".
I believe moving that route definition after your resource route definitions should resolve your issue.
Give it a try & let us know if this gets resolved.
As from your described routes, other then home routes are grouped with admin middleware.
Just confirm with your admin middleware about 404 redirection.
Update
Check your admin middleware and update it with below code:
public function handle($request, Closure $next)
{
if ((Auth::check()))
{
//Here, YOURADMINROLE replace with your actual admin role..
if ((Auth::user()->hasRole('YOURADMINROLE')))
{
return $next($request);
}
}
App::abort(403, 'Access denied');
}
I am new to laravel runing a project in it,i got error when i enter a module name to url NotFoundHttpException in RouteCollection.php line 161
And here is my routes.php file Code:
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/
Route::get('/', ['as' => 'home', 'uses' => 'Landing#index']);
Route::get('/buyerregistration',['as' => 'buyerregistration', function () {
return view('buyerregistration');
}]);
Route::get('owarehouse/{id}', ['as' => 'owarehouse',function () {
return view('owarehouse');
}]);
Route::get('/SMM', ['as' => 'SMM',function () {
return view('SMM');
}]);
Route::get('productconsumer/{id}/{openwish_id?}',array(
'as' => 'productconsumer',
'uses' => 'ProductController#productconsumer'));
I have .htacces file in my /public folder as:
<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]
</IfModule>
Can anyone help me to sort out this,
Thanks
Enable Mod_rewrite in your Xampp/Wampp's Apache.
Go to {xampp_dir/wampp_dir}/apache/conf/httpd.conf and find the line
#LoadModule rewrite_module modules/mod_rewrite.so and remove the # before it.
Allow Apache to Overwrite the htaccess file from anywhere. Find the line
AllowOverride None and change it to AllowOverride All
Try localhost/Opensupermall/public/SMM
The code here points to your views after the public folder.
Now,the best practice would be in production to make your server's root folder to point the /public/ folder
Route::get('/SMM', ['as' => 'SMM',function () {
return view('SMM');
}]);
So you just type your route names after your root directory name.
I have a route group for the prefix admin. I want that if the URL http://www.example.com/admin/ is entered it by default loads the login page residing at http://www.example.com/admin/login. The login page is actually a controller, but I don't mind if the admin/ redirects to admin/login or routes to its controller directly. From other answers I saw here it seems that redirection is better to make sure links are not messed up.
I have tried various solutions with both routing and redirection, including the solution suggested here but I am alwas getting Error 404. What is the recommended proper way to achieve this?
My route group looks like this:
Route::group(array('prefix' => 'admin', 'namespace' => 'MyNamespace\Controllers\Admin'), function()
{
//the following work fine
Route::get('login', array('uses' => 'AdminLoginController#showLogin'));
Route::post('login', array('uses' => 'AdminLoginController#doLogin'));
Route::get('logout', array('uses' => 'AdminLoginController#doLogout'));
//other resource routes for the respective admin pages
});
Outside the route group I added the following, so that even http://www.example.com/admin without the trailing slash goes to the login page, which works fine.
Route::get('admin', function() { return Redirect::to("admin/login"); });
The problem is with http://www.example.com/admin/ that is giving Error 404. I tried all the following (separately obviously), and none works. All of them were inside the route group.
Route::get('/', function() { return Redirect::to("admin/login"); });
Route::get('', function() { return Redirect::to("admin/login"); });
Route::get('/', function() { return Redirect::to("login"); });
Route::get('', function() { return Redirect::to("login"); });
Route::get('/', array('uses' => 'AdminLoginController#showLogin'));
Route::get('', array('uses' => 'AdminLoginController#showLogin'));
I also tried this outside the route group:
Route::get('admin/', function() { return Redirect::to("admin/login"); });
None of them work. What is the right way to set a default route for a route group with a prefix subdirectory?
use this code in .htaccess
so your server will redirect url's with trailing slashes to url without.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
# redirect everything to url without trailing slash
RewriteCond %{HTTPS} =on
RewriteRule ^(.+)$ - [env=ps:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.+)$ - [env=ps:http]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_METHOD} ^GET
RewriteRule ^(.+)/$ %{ENV:ps}://%{SERVER_NAME}/$1 [R=301,L]
# pretty urls
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php [L]
</IfModule>
by default laravel firstly did redirection, but later was removed.
Having problem with subdomains :(
In Routes:
Route::group(['domain' => 'www.app.me'], function(){
Route::get('/', 'SiteController#index');
Route::get('/{uri}', 'ShortnerController#redirect');
});
Route::group(['domain' => 'app.me'], function(){
Route::get('/', 'SiteController#index');
Route::get('/{uri}', 'ShortnerController#redirect');
});
Route::group(['domain' => 'platform.app.me'], function(){
Route::get('/', 'PageController#index')->before('auth');
});
Route::group(array('domain'=>'agent.app.me'), function(){
Route::get('/', 'AgentController#index')->before('auth');
});
When I go to app.me or www.app.me it shows the SiteController#index
If I go to agent.app.me it shows AgentController#index
But the problem is if I go to platform.app.me it redirects to app.me
How to solve this?
In cPanel a managed redirections like this:
Subdomains.Root Domain Document Root Redirection
agent.app.me /public_html not redirected
platform.app.me /public_html not redirected
Try changing the order. The first matched route will always be the one used. Also, if app.me is just going to use the same routes as www., why not use htaccess to force www. and have one less route group to maintain?
So, routes.php:
Route::group(['domain' => 'platform.app.me'], function(){
Route::get('/', 'PageController#index')->before('auth');
});
Route::group(['domain'=>'agent.app.me'], function(){
Route::get('/', 'AgentController#index')->before('auth');
});
Route::group(['domain' => 'www.app.me'], function(){
Route::get('/', 'SiteController#index');
Route::get('/{uri}', 'ShortnerController#redirect');
});
Notice that I changed your use of array() to [] in the agent.app.me route group for consistency as you were mixing the two.
And .htaccess:
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
# Enforce www where not using www or a valid sub domain or tld
RewriteCond %{HTTP_HOST} !^(www|agent|platform)\.app\.(me|dev)$ [NC]
RewriteRule ^(.*)$ http://www.app.me/$1 [L,R=301]
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>