programing

내 경로가 404를 반환합니다. 어떻게 해결할 수 있습니까?

nasanasas 2020. 10. 25. 12:23
반응형

내 경로가 404를 반환합니다. 어떻게 해결할 수 있습니까?


방금 라 라벨 프레임 워크를 배우기 시작했는데 라우팅에 문제가 있습니다.

작동하는 유일한 경로는 기본적으로 Laravel에 연결된 기본 홈 경로입니다.

Windows에서 WAMP를 사용하고 있으며 PHP 5.4.3 및 Apache 2.2.22를 사용하고 있으며 mod_rewrite도 활성화하고 application.php 구성 파일에서 'index.php'를 제거하여 빈 문자열을 남겨 둡니다.

User 라는 새 컨트롤러를 만들었습니다 .

class User_Controller extends Base_Controller {

    public $restful = true;

    public function get_index() 
    {
        return View::make('user.index');
    }
}

몇 가지 기본 HTML 코드를 사용하여 application / views / user /에 index.php 라는 뷰 파일을 만들었 으며 route.php에 다음을 추가했습니다.

Route::get('/', function () {
    return View::make('home.index');
});

Route::get('user', function () {
    return View::make('user.index');
});

http://localhost/mysite/public웹 브라우저에서 루트 ( )를 방문하면 첫 번째 경로가 제대로 작동하지만 두 번째 경로로 이동하려고 http://localhost/mysite/public/user하면 404 찾을 수 없음 오류가 발생합니다. 왜 이런 일이 일어날까요?


대신 경로 파일에 이것을 추가해 보셨습니까 Route::get('user', "user@index")?

전과 텍스트의 단편은 @, user이 경우, 사용자 제어 및 후 텍스트의 부분 페이지를 지시한다 @, index상기 스크립트에 지시한다 user기능 public function get_index().

을 (를) 사용 $restful하고있는 것을 확인 Route했습니다 Route::any('user', 'user@index'). 이 경우을로 설정할 수 있습니다 . 이렇게하면 둘 다 따로 작성하는 대신 POST둘 다 처리합니다 GET.


Ubuntu LAMP 설치에서 다음 두 가지 변경 사항으로이 문제를 해결했습니다.

  1. 아파치 서버에서 mod_rewrite 활성화 : sudo a2enmod rewrite.
  2. /etc/apache2/apache2.conf를 편집 하여 / var / www 디렉토리 (내 기본 문서 루트)에 대한 "AllowOverride"지시문을 변경합니다.AllowOverride All

그런 다음 Apache 서버를 다시 시작합니다. service apache2 restart


WAMP를 사용하여 wamp 아이콘-> apache-> apache 모듈-> 스크롤 및 rewrite_module 확인 LoadModule 다시 시작 rewrite_module

"rewrite_module"을 활성화하면 서버 응용 프로그램이 자동으로 다시 시작됩니다.


다음 사항을 확인하려고 했습니까?

http://localhost/mysite/public/index.php/user 

일하고 있었습니까? 그렇다면 모든 경로의 폴더에 대문자가 없는지 확인하십시오. 나는 같은 상황이었고 문자를 소문자로 변환하는 것이 도움이되었습니다.


EasyPHP를 사용하여 동일한 문제가 발생했습니다. AllowOverride All에서 내 <Directory>블록에 지정해야 함을 발견 했습니다 httpd.conf. 이것이 없으면 Apache는 때때로 .htaccess.

내 것이 이렇게 생겼어 ...

<Directory "D:/Dev">
    Options FollowSymLinks Indexes
    #### NEXT IS THE CRUCIAL LINE ####
    AllowOverride All                  
    Order deny,allow
    Allow from 127.0.0.1
    Deny from all
    Require all granted     
</Directory>

이동 root/public/.htaccess시도 할 root/.htaccess있으며 작동합니다.


노선

컨트롤러에서 관리하지 않는 특정 경로를 정의하는 데 사용합니다.

컨트롤러

전통적인 MVC 아키텍처를 사용하고 싶을 때 사용하십시오.

문제에 대한 해결책

컨트롤러 작업에 대해 특정 '명명 된'경로를 원하지 않는 한 컨트롤러를 경로로 등록하지 않습니다.

컨트롤러 작업에 대한 경로를 생성하는 대신 컨트롤러를 등록하기 만하면됩니다.

Route::controller('user');

이제 컨트롤러가 등록되어, 당신은 탐색 할 수 있습니다 http://localhost/mysite/public/user당신이 get_index실행됩니다.

한 번에 모든 컨트롤러를 등록 할 수도 있습니다.

Route::controller(Controller::detect());

에서 " RewriteBase"를 잊지 마세요 public/.htaccess.

예 :

Options +FollowSymLinks
RewriteEngine On
RewriteBase /your/folder/public

좋아, 그래서 하루 조금 ​​넘게이 문제에 대해 머리를 두들겨서 ... 나는 일어나서 어제해야 할 일을했고, 무슨 일이 있었는지 디버그했습니다!

Laravel이 여기서 시도 index.php하는 것은 Route로 지정된 경로 바로 앞에 파일을 삽입하는 것 입니다. 예를 들어, 브라우저 Route::get('/account/create', ...,에서 say 를 지정하고 localhost/laravel/authenticate/public/account/create을 실행 localhost/authenticate/public/index.php/account/create하면 laravel은을 (를) 실행하려고 하지만이를 수행합니다. Apache는 해당 요청을 확인해야 /wamp/www/laravel/laravel/authentication/public합니다. laravel 앱이 실제로 설치되어 있지만 후행 public은 대체가 필요한 곳입니다) 'RewriteRule'을 적용해야합니다.

고맙게도 laravel .htaccess은 앱 public폴더 편리한 파일 에 올바른 재 작성 규칙을 제공 합니다. 문제는 '.htaccess'파일의 코드가 WAMP가 즉시 구성되는 방식으로 작동하지 않는다는 것입니다. 이 SEEMS가이 스레드의 맨 위에있는 muvera가 제안한 문제인 이유는 rewrite_module 코드가 아파치에 의해로드되어야 RewriteRule작동 할 것입니다. 도대체 말이 되네요.

이해가되지 않습니다 부분 : 간단 stopping하고 restarting아파치 서비스를 선택하지 않습니다이 WAMP이 RewriteRule의에 옳은 일을하는 데 필요한 변경 - 내가 아는 한, 나는이 여러 번 시도!

What DOES work: make the changes suggested by muvera (see top of thread) to load the correct modules. Then, reset your whole Windows session, thus dumping Apache out of memory altogether. Restart (reload) WAMP, and VOILA! the fix works, the correct RewriteRule is applied, yada, yada; I'm living happily ever after.

The good news out of all this: I know a LOT more about .htaccess, RewriteRule, and httpd.conf files now. There is a good (performance) argument for moving the logic from your app's public .htaccess file, and putting it into a Directory ... section of your httpd.conf in your Apache 'bin' folder BTW (especially if you have access to that folder).


Try enabling short php tags in your php.ini. WAMP has them off usually and laravel needs them on.


Route::get('/', function()
{
return View::make('home.index');
});

Route::get('user', function()
{
return View::make('user.index');
});

change above to

Route::get('user', function()
{
return View::make('user.index');
});

Route::get('/', function()
{
return View::make('home.index');
});

You have to use '/'(home/default) at the end in your routes


you must be using Laravel 5 the command

  class User_Controller extends Controller {
  public $restful = true;
  public function get_index(){
  return View('user.index');
  }
  }

and in routes.php

  Route::get('/', function()
  {
  return view('home.index');
  });

  Route::get('user', function()
  {
  return view('user.index');
  });

Laravel 5 command changes for view and controller see the documentation i was having same error before


Just Run in your terminal.

 composer dump-autoload

The Main problem of route not working is there is mod_rewrite.so module in macos, linux not enabled in httpd.conf file of apache configuration, so can .htaccess to work. i have solved this by uncomment the line :

LoadModule rewrite_module libexec/apache2/mod_rewrite.so

Remove the # from above line httpdf.conf. Then it will works. enjoy!


I think you have deleted default .htaccess file inside the laravel public folder. upload the file it should fix your problem.


the simple Commands with automatic loads the dependencies

composer dump-autoload

and still getting that your some important files are missing so go here to see whole procedure

https://codingexpertise.blogspot.com/2018/11/laravel-new.html


If you're using Vagrant though Homestead, it's possible there was an error mounting the shared folder. It looks like Vagrant takes your files from that folder and swaps out the files that are actually on the host machine on boot, so if there was an error, you're essentially trying to access your Laravel installation from when you first made it (which is why you're only getting "home"- that was generated during installation).

You can easily check this by sshing into your vm and checking the routes/web.php file to see if it's actually your file. If it isn't, exit out and vagrant halt, vagrant up, and look for errors on boot.

참고URL : https://stackoverflow.com/questions/11791375/my-routes-are-returning-a-404-how-can-i-fix-them

반응형