Laravel 5.2 : only route '/' works in wind

2019-07-09 04:49发布

问题:

today I had a problem when I try to access my project route in windows iis server.

my application url is : demo.example.com/testing/

the root routing is working '/', but not with the other.

for example, if I try to clicking menu with '/home/' route, the url will be like demo.example.com/home' , the 'testing' is gone somehow.

PS : I already remove the 'public' folder with moving all of files in public folder outside, and moving the other files into new folder.

Route example:

Route::get('/', 'frontend\frontController@index');

Route::get('/login', 'frontend\frontController@login');

Thanks for helping !

回答1:

it comes down to URL rewrites. I had the exact same issue, and I needed to add a rule in web.config:

<rule name="routes" stopProcessing="true">
                  <match url="^(.*)$" ignoreCase="false" />
                  <conditions logicalGrouping="MatchAll">
                      <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
                      <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" />                     
                  </conditions>
                  <action type="Rewrite" url="public/index.php/{R:1}" />

                </rule>

from this blog post: https://laracasts.com/discuss/channels/servers/iis-8-laravel-webconfig



回答2:

You are not supossed to place laravel in a subfolder. Your subdomain should directly point to the application without any further subfolders since Laravel will use absolute paths to navigate to your routes. e.g.

Route::get('home', ...)

will always navigate to yourdomain.com/home even though it actually maches yourdomain.com/laravel/home unless you make a lot of changes to your setup.



回答3:

Can you access the login page by demo.example.com/testing/public/index.php?/login

If yes, the problem probably in your server configuration or .htaccess

I've just encountered the same problem, for me enabling mod_rewrite for apache2 fix it.

You should probably read:

https://laravel.com/docs/5.0/configuration#pretty-urls

Can't route properly in Laravel

Can't access URL in Laravel routes

The last thing, You shouldn't do this thing below.

PS : I already remove the 'public' folder with moving all of files in public folder outside, and moving the other files into new folder.

Stop messing with the folder structure. Do not do things you don't know!