Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Reactjs .htaccess 500路由api时发生内部服务器错误_Reactjs_Regex_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

Reactjs .htaccess 500路由api时发生内部服务器错误

Reactjs .htaccess 500路由api时发生内部服务器错误,reactjs,regex,apache,.htaccess,mod-rewrite,Reactjs,Regex,Apache,.htaccess,Mod Rewrite,我目前正在本地apache服务器上运行php,带有React前端 这就是我当前的.htaccess布局: Options -MultiViews RewriteEngine On RewriteRule ^api/(.*)$ api/$1\.php [L] RewriteCond %{REQUEST_URI} !^/api.*? RewriteRule ^ index.html [QSA,L] 最基本的条件是,路由可以在我的React应用程序中工作。然后我将生产

我目前正在本地apache服务器上运行php,带有React前端

这就是我当前的
.htaccess
布局:

Options -MultiViews
    RewriteEngine On
    RewriteRule ^api/(.*)$ api/$1\.php [L]
    RewriteCond %{REQUEST_URI} !^/api.*?
    RewriteRule ^ index.html [QSA,L]
最基本的条件是,路由可以在我的React应用程序中工作。然后我将生产构建并将其复制到我的htdocs中

但是,路由是有效的,我希望能够调用
/api
目录中的.php文件,而不使用文件扩展名。所以我希望
/api/
之后的任何内容都被重定向到输入的内容,然后是
.php

例如,
/api/authentication
将转到
/api/authentication.php
/api/register
将转到
/api/register.php
,依此类推

在当前的设置中,我在请求
/api/authentication
等时遇到500个内部服务器错误


我的
.htaccess
文件有问题吗?

在匹配
*
时,您的第一条规则正在循环。您可以使用:

Options -MultiViews
RewriteEngine On

RewriteRule ^index\.html$ - [L,NC]

RewriteCond %{REQUEST_URI} !\.php$ [NC]
RewriteRule ^api/(.+)$ api/$1.php [L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !^api index.html [L,NC]

RewriteCond%{REQUEST\u URI}!\。当URI以
结尾时,php$[NC]
将跳过重写。php

请在
.env
文件中设置
APP_DEBUG=true
,并检查错误。使用此解决方案不会加载任何内容。只有空白页。清空缓存并硬加载,检查网络选项卡,没有404错误,但我仍然得到空白页。不,我没有,这些都在/静态文件夹中。让我们来看看。