i installed a project on my www folder in wamp , but when i add new route and try to get it wil the browser i got page not found , i copied all laravel 4 files to local folder exclude publi folder and i put its content on www , and try my route , i got the same error :
the routes :
<?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 Closure to execute when that URI is requested.
|
*/
Route::get('/', function()
{
return View::make('hello');
});
Route::get('about', function()
{
return View::make('hello');
});
when i get to " localhost " , it works fine but when i get to " localhost/about" i got page not found and i modified paths and index files and same issue
you can enable rewrite_mod :
Open the httpd.conf file and search for
"rewrite"
, then remove
"#"
at the starting of the line,so the line looks like.
LoadModule rewrite_module modules/mod_rewrite.so
then restart the wamp.
It's likely that rewrite_mod is disabled in your Apache installation.
Try enabling it. Here's how to do it
Related
What is the proper way to add a subdomain into your routes? I have a laravel/homestead project working on my local computer but when I move it to HostGator, a shared host server, it no longer works. Well the home page works but the links to the sub-pages don't.
For example, the following route works fine on my local version:
Route::get('/appointments', 'AppointmentController#index');
But if I use that route on the remote server, it takes it to tekknow.net/appointments instead of tekknow.net/medaverter/appointments.
So I followed instructions from here:
https://laravel.com/docs/5.6/routing#route-group-sub-domain-routing
and added a prefix like this:
Route::prefix('MedAverter')->group(function() {
Route::get('/appointments', 'AppointmentController#index');
});
But that doesn't work either. It also goes to /tekknow.net/appointments
I also tried changing the route to this:
Route::get('/MedAverter/appointments', 'AppointmentController#index');
But that also went to tekknow.net/appointments
Anybody know what I'm doing wrong?
EDIT: I went onto my HostGator cPanel and looked at all my subdomains and saw that my subdomain root was medaverter.tekknow.net which is linked to Document root of medaverter.tekknow.net/MedAverter which gets redirected to http://www.tekknow.net/MedAverter. So I renamed my folder from medaverter to MedAverter to match the subdomain redirection.
Here is a screenshot showing what I see in cPanel for columns Subdomains.Root Domain, Document Root, and Redirection
When you try php artisan route:list | grep appointments,
it prints:
[~/www/MedAverter]# php artisan route:list | grep appointments
| | GET|HEAD | MedAverter/appointments | | App\Http\Controllers\AppointmentController#index | web |
That means your route MedAverter/appointments is working for laravel.
Error 404 means route cannot be found.
So I think that's something wrong with your nginx configuration.
When I try http://tekknow.net/MedAverter/MedAverter/appointments.
It has really found the route with error 500.
So, I think you have defined this code in your nginx configuration:
location = / {
rewrite ^ https://tekknow.net/MedAverter;
}
Solution 1:
Change back to rewrite ^ https://tekknow.net/; in nginx configuration.
(I'm not familiar with hostGatar cPanel, but I think you can change medaverter.tekknow.net/MedAverter redirected to http://www.tekknow.net/`)
And in your laravel project, you need to keep prefix MedAverter to appointments.
Solution 2:
Keep the rewrite code. It means you don't need to change the cPanel redirect.
And remove prefix MedAverter in laravel routes. HostGatar(Nginx) will automatically redirect with this prefix MedAverter for appointments.
Clear all caches
The problem you're getting can be due to cache. So, make sure that's not the problem by running
php artisan route:clear && php artisan view:clear && php artisan config:clear && php artisan cache:clear && php artisan clear-compiled
Base URL
If you want to change the base URL of your Laravel app, that's something already asked.
Multiple Path Prefixes
In this case you have a more than one route with the same prefix in their path. If that's the case, you can use route groups to simplify the structure.
Route::prefix('medaverter')->group(function () {
Route::get('/', function () {
// Path /medaverter
});
Route::get('appointments', function () {
// Path /medaverter/appointments
});
});
This would go to, respectively, tekknow.net/medaverter and tekknow.net/medaverter/appointments. You could also create another prefix, like testing, configure in the same way and go to tekknow.net/testing or tekknow.net/testing/whatever.
Namespace prefixes
When you’re grouping routes by route prefix, it’s likely their controllers have a similar PHP namespace. In the medaverter example, all of the medaverter routes’ controllers might be under a Medaverter namespace.
Route::namespace('Medaverter')->group(function () {
// App\Http\Controllers\Medaverter\AppointmentController
Route::get('medaverter/appointments', 'AppointmentController#index');
});
u can use route groups for that here is a sample try this:
Route::group(['prefix' => 'medaverter'], function () {
Route::get('/appointments', [AppointmentController::class, 'index'])->name('index');
});
or
Route::group(['prefix' => 'medaverter'], function () {
Route::get('/appointments', 'AppointmentController#index');
});
I just made a fresh laravel project from scratch and the first thing I did was, I executed
php artisan make:auth
then migrate it
php artisan migrate
and open the project in the browser and hit login it says
Sorry, the page you are looking for could not be found.
Here is the error screenshot:
and here is the routes/web.php
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController#index')->name('home');
Maybe it works for you
First, go to the project directory and open the public folder and copy .htaccess and index.php to the main directory.
And Paste it Here in the Main Directory.
Then open the index.php and replace
require __DIR__.'/../vendor/autoload.php';
and $app = require_once __DIR__.'/../bootstrap/app.php';
with require __DIR__.'/vendor/autoload.php';
and
$app = require_once __DIR__.'/bootstrap/app.php';
and save it. then run the project in the browser
Localhost:8080/bsms/login.
Use this command:
php artisan serve
If you have PHP installed locally and you would like to use PHP's built-in development server to serve your application, you may use the serve Artisan command. This command will start a development server at http://localhost:8000
Later you can check in browser like this: http://localhost:8000/login
If you have to check without artisan serve
you can check like this(bsms is your laravel-project-name):http://localhost/bsms/public/login
you must have a configuration like this in your .htaccess file
When i hit url the route needs to be configured with a prefix folder name i.e "laravel/"
for example
For Url:
http://localhost/laravel/someurl
Route::get('laravel/someurl', function () {
return "asdasd";
});
How to remove the folder name for appearing in routes
if you just want add some prefix you can use below code for group of code
Route::group(['prefix' => 'app'], function () {
Route::get('package_type',['as'=>'package_type','uses'=>'UserController#package_type']);
});
for getting this root you need to hit
your_url.com/app/package_type
hope this is what you need
If you want to remove folder prefix, you should set web server document root to public folder. For example, if use php-cli to run PHP simple server, use option -t to change document root:
php -S localhost:80 -t /path/to/laravel-project/public
Now, you can see that prefix is gone.
Similarly, if you use other servers such as Apache or Nginx, you only need to modify the settings.
Quick question,
EDIT: I do not know how to access other routes besides '/'
Here are the routes I want to access
Route::get('/', 'HomeController#index');
Route::get('users', 'UserController#index');
Route::get('foo', function()
{
return 'Hello World';
});
Here is my routes. Via php artisan routes
I can successfully access localhost/cartraderlaravel/public
It takes me to HomeController#index
when I try to access foo or users I get
I have tried
localhost/cartraderlaravel/public/users
localhost/cartraderlaravel/users
localhost/cartraderlaravel/foo
localhost/cartraderlaravel/public/foo
All of these return a "Not Found" error. Help anyone?
You should point your root directory to cartraderlaravel/public in WAMP so that you need not to visit localhost/cartraderlaravel/public. To do that in WAMP follow :
Click on WampServer icon in taskbar
Select Apache > httpd.conf from the pullup
Search for the term “DocumentRoot”
Change the DocumentRoot path to your custom directory
Search again for “DocumentRoot” again same procedure
Save your changes and “Restart All Services”
Further research shows this is a common problem with WAMP. Something to do with Apache settings. I have moved to using a virtual network and everything works now
I have just set up a new laravel 4 project and I can't seem to get my routes to work.
I have the following code in my routes.php file.
Route::get('test', function()
{
return 'test';
});
Route::get('/', function()
{
return View::make('hello');
});
But if I go to localhost:8888/laravel4 I get a directory listing instead of the '/' route.
If I go to localhost:8888/laravel4/test I get The requested URL /laravel4/test was not found on this server.
I am using MAMP with php 5.5.3 for my localhost.
The entry point is in the public directory
So you go to
localhost:8888/laravel4/public/
to get the / route
and
localhost:8888/laravel4/public/test
to the test route.
Otherwise, you should set up a vhost (Don't know how to do in Mac) and point it to the public directory of your laravel project