简体   繁体   English

在此服务器上找不到请求的 URL /ProjectName/users。 Laravel

[英]The requested URL /ProjectName/users was not found on this server. Laravel

I am following the quickstart of laravel and it said "type /users" but not working for me.我正在关注 laravel 的快速入门,它说"type /users" ,但对我不起作用。 I have wrote in the browser, http://DomainServer/ProjectName/users and it throws:我在浏览器中写了http://DomainServer/ProjectName/users并抛出:

The requested URL /ProjectName/users was not found on this server.在此服务器上找不到请求的 URL /ProjectName/users。 Laravel Laravel

I tried the following,我尝试了以下,

To enable the apache module mod_rewrite and also does not work.启用 apache 模块mod_rewrite也不起作用。

Steps for Apache Web Server and Laravel in Linux Environment. Linux 环境中 Apache Web Server 和 Laravel 的步骤。

  1. Open httpd.conf打开 httpd.conf

     sudo vim /etc/httpd/conf/httpd.conf # for debian users: /etc/apache2/apache2.conf
  2. Make sure the DocumentRoot is pointing to the laravel project's public directory确保 DocumentRoot 指向 laravel 项目的公共目录

  3. Add the Directory element for that path and Allowoverride All... as follows为该路径添加 Directory 元素并 Allowoverride All... 如下

    DocumentRoot "/var/www/html/laravel/public/" <Directory "/var/www/html/laravel/public"> Allowoverride All </Directory>
  4. Open .htaccess from ../laravel/public/ and make sure it has the following从 ../laravel/public/ 打开 .htaccess 并确保它具有以下内容

    <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>
  5. Restart httpd services重启httpd服务

    sudo service httpd restart
  6. Now http://DomainServer/users will work in your browser.现在http://DomainServer/users将在您的浏览器中工作。

Find httpd.conf and change the <Directory> element from找到 httpd.conf 并将<Directory>元素从

<Directory "/var/www/html/">
Allowoverride None
</Directory>

to

<Directory "/var/www/html/">
Allowoverride All
</Directory>

Then it works after restart the apache without change the DocumentRoot .然后它在重新启动 apache 后工作而不更改DocumentRoot

First find the htaccess file in your Laravel project首先在你的 Laravel 项目中找到 htaccess 文件

next add the following coding in htaccess file接下来在 htaccess 文件中添加以下代码

<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]

save the htaccess file保存 htaccess 文件

and restart the apache server using following code并使用以下代码重新启动apache服务器

sudo service apache2 restart

remember htaccess file and index.php file must be available in same folder in your project记住 htaccess 文件和 index.php 文件必须在你的项目的同一个文件夹中

如果您尝试 .../public/index.php/your_page,默认 url 在您的页面之前有一个前缀“index.php”,它将运行,因此如果您使用 appache 编写您的 url,则需要添加模块重写这个前缀

尝试将浏览器指向http://DomainServer/ProjectName/public/users - “public”文件夹是 Laravel 应用程序的默认“入口点”。

确保您在 Apache 中启用了 mod_rewrite。

For me i enabled the mod_rewrite and it worked for me well.对我来说,我启用了 mod_rewrite 并且它对我很有效。 Enable mod_rewrite for Apache: cd /etc/apache2/sites-available/ sudo a2enmod rewrite为 Apache 启用 mod_rewrite: cd /etc/apache2/sites-available/ sudo a2enmod rewrite

in my case I wanted to get this route as not authenticated user .在我的情况下,我想以未经身份验证的用户身份获得这条路线。 RouteServiceProvider has default : RouteServiceProvider 有默认值:

/**
 * Define the "api" routes for the application.
 *
 * These routes are typically stateless.
 *
 * @return void
 */
protected function mapApiRoutes()
{
    Route::prefix('api')
        ->middleware('api')
        ->namespace($this->namespace)
        ->group(base_path('routes/api.php'));
}

which means you need to add that prefix " api/ " to your url, say:这意味着您需要将该前缀“ api/ ”添加到您的网址中,例如:

http://yourdomain.com/api/route_url_part

Then put route to api.php , not web.php wich is auth 'middlwared'然后把路由放到api.php ,而不是web.php ,这是 auth 'middlwared'

(optionally for Android emulators) if you are trying to do that in, say, android emulator you have to shut down server and start it as: (可选用于 Android 模拟器)如果您尝试在 android 模拟器中执行此操作,则必须关闭服务器并将其启动为:

php artisan serve --host=0.0.0.0

and in java android url instead of localhost put in the ip retrived from prompt window's ipconfig command.并在java android url而不是localhost中放入从提示窗口的ipconfig命令检索的ip。 Say mine was 192.168.0.106 ( IPv4 Address one).假设我的是192.168.0.106IPv4 地址一)。 Then it will work.然后它会起作用。

$ sudo nano /etc/apache2/apache2.conf <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None Require all granted $ sudo nano /etc/apache2/apache2.conf <Directory /var/www/> Options Indexes FollowSymLinks AllowOverride None 要求全部授予

Change to改成

<Directory /var/www/> Options Indexes FollowSymLinks AllowOverride All Require all granted <Directory /var/www/> 选项索引 FollowSymLinks AllowOverride All 要求全部授予

$ sudo a2enmod rewrite $ sudo systemctl restart apache2 $ sudo a2enmod rewrite $ sudo systemctl restart apache2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 “在此服务器上找不到请求的URL / projectname / pagename /。”WordPress网站上的问题 - “The requested URL /projectname/pagename/ was not found on this server.” issue on WordPress website 找不到在此服务器上找不到请求的URL / emr / login。 在Laravel - Not Found The requested URL /emr/login was not found on this server. in Laravel 错误:在此服务器上找不到请求的 URL /login。 (Laravel) - Error: The requested URL /login was not found on this server. (Laravel) 在此服务器上找不到请求的URL。 在PHP codeigniter上 - The requested URL was not found on this server. on php codeigniter 在此服务器上找不到请求的URL。 阿帕奇 - The requested URL was not found on this server. Apache 在此服务器上找不到请求的 URL。 - php,wordpress - The requested URL was not found on this server. - php, wordpress 在此服务器上找不到请求的URL。 Magento与oAuth - The requested URL was not found on this server. Magento with oAuth Apache:在此服务器上找不到请求的 URL /。 阿帕奇 - Apache: The requested URL / was not found on this server. Apache Laravel给我找不到对象! 在此服务器上找不到请求的URL。 404错误 - Laravel gives me Object not found! The requested URL was not found on this server. 404 error 未找到 Object。 在此服务器上未找到请求的 URL。 本地主机 Laravel Xampp 问题 - Object not found! The requested URL was not found on this server. localhost Laravel Xampp Issue
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM