php – IIS服务器,如何为Laravel 5配置url重写?
发布时间:2020-12-14 19:40:51 所属栏目:大数据 来源:网络整理
导读:目前,Uni只提供了一个IIS服务器来托管我们的php网站,我们想要使用Laravel框架,它确实在主页上工作.但不是任何其他控制器. 我的公用文件夹中的当前web.config是, configuration system.webServer rewrite rules rule name="Imported Rule 1" stopProcessing="
目前,Uni只提供了一个IIS服务器来托管我们的php网站,我们想要使用Laravel框架,它确实在主页上工作.但不是任何其他控制器.
我的公用文件夹中的当前web.config是, <configuration> <system.webServer> <rewrite> <rules> <rule name="Imported Rule 1" stopProcessing="true"> <match url="^(.*)/$" ignoreCase="false" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> </conditions> <action type="Redirect" redirectType="Permanent" url="/{R:1}" /> </rule> <rule name="Imported Rule 2" stopProcessing="true"> <match url="^" ignoreCase="false" /> <conditions> <add input="{REQUEST_FILENAME}" matchType="IsDirectory" ignoreCase="false" negate="true" /> <add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" /> </conditions> <action type="Rewrite" url="index.php" /> </rule> </rules> </rewrite> </system.webServer> </configuration> 我的路线是, Route::get('/',function () { return view('welcome'); }); Auth::routes(); Route::get('/home','HomeController@index')->name('home'); 我不太了解IIS,所以你有任何想法来配置它以使其工作吗? 附: 提前致谢. 解决方法
最后我解决了这个问题,这不是一个完美的方式,但它确实奏效了.
<rule name="rewrite all requests to index.php" stopProcessing="true"> <match url="^(.*)$" ignoreCase="false" /> <conditions logicalGrouping="MatchAll"> <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" /> </conditions> <action type="Rewrite" url="index.php" appendQueryString="true" /> </rule> <rule name="Redirect / to index.php" stopProcessing="true"> <match url="^" ignoreCase="false" /> <action type="Rewrite" redirectType="Permanent" url="index.php" /> </rule> 正如我在开始时提到的,它不是一个完美的解决方案,它将所有URL重写为index.php,所以URL不漂亮,就像, > a.com/login – > a.com/index.php/login 因为我对IIS配置/重写不是很熟悉,所以必须有一些更好的解决方案,所以改进这行配置文件的建议会很棒. 无论如何,它在您无权设置IIS服务器的情况下工作. 它应该使Laravel项目在任何IIS服务器上运行,而无需更改服务器的设置. 参考文献 > IIS rewrite and asp.net route (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |