简体   繁体   English

使用react + react-router-dom获取PHP服务器以为所有路由提供index.html

[英]Get php server to serve index.html for all routes using react + react-router-dom

Typically I make a website with reactjs + node + express, which is the usual combination. 通常,我用reactjs + node + express创建一个网站,这是通常的组合。 Then I deploy to Heroku and all is well. 然后我部署到Heroku,一切都很好。

However, at request I have done reactjs front end with php back end deploying to cpanel and have run into the 404 issue with client side routing - if navigating directly to non-home-page route (let's say domain/quote) there is nothing on the server with that url and 404 error is thrown. 但是,应要求,我已经完成了将php后端部署到cpanel的reactjs前端,并且遇到了客户端路由的404问题-如果直接导航到非主页路由(比如说域/引用),则没有任何内容具有该网址和404错误的服务器。

I found the principle of the solution here but this and all other answers I've found refer to node+express back ends only. 我在这里找到了解决方案的原理,但是我发现的所有其他答案仅涉及node + express后端。

Any way this can be done with a straight php back end? 任何方式都可以通过直接的php后端来完成? I am not using laravel or another framework. 我没有使用laravel或其他框架。

Also, though I have learned a lot recently I still consider myself a beginner - my apologies if the answer ends up being somewhat obvious. 另外,尽管我最近学到了很多东西,但我仍然认为自己是一个初学者-如果答案最终有些明显,我深表歉意。

Ok, fellow php back end users, I did find a solution and it is in the .htaccess file. 好的,php后端用户,我确实找到了一个解决方案,它位于.htaccess文件中。

Add it to public_html in cpanel and set permissions to 755 or to execute. 将其添加到cpanel中的public_html并将权限设置为755或执行。

More information here . 更多信息在这里

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM