【发布时间】:2021-02-28 14:39:55
【问题描述】:
我的网站包含路线,点击按钮后,它会将您发送到/start 路线。
它在 localhost 中运行良好 - 这对 htaccess 很可疑,但在我的服务器中它路由到 /start 并返回 404。
PHP 代码有效,因为它意味着向我发送电子邮件并发送给我(也在我的服务器托管中),但只有路由不起作用。
fetch('https://devcore.co.il/server/mail.php', {
method: 'POST',
redirect: 'follow',
body: new URLSearchParams(formData)
})
.then(function(response) {
if (response.status >= 200 && response.status < 300) {
return response.text()
}
throw new Error(response.statusText)
})
.then(function(response) {
console.log(response);
if(response === 'success'){
history.push("/start");
history.go(0);
executeScroll();
}
})
.catch(function(err) {
console.log(err);
});
我已经使用 fetch 来应用页面路由,在 localhost 中可以正常工作。
HTACCESS
<IfModule mod_headers.c>
Header set Access-Control-Allow-Origin "*"
Header set Access-Control-Content-Type "*"
Header set Access-Control-Accept "*"
# This should enable the authentication header
Header set Access-Control-Allow-Credentials "true"
</IfModule>
我的路线
<Route path="/start">
//Implementing my `/start` route
</Route>
是什么导致页面在服务器托管上进入 404 但在本地主机上工作?
【问题讨论】:
-
您发布的
.htaccess文件实际上并没有做任何事情,那么请求如何通过 React 路由? “它在 localhost 中工作正常 - 这对 htaccess 可疑” - “对 localhost 上的 htaccess? Do you have any other.htaccess` 文件或指令可疑”是什么意思? -
@MrWhite 我没有任何其他 htaccess,这里的 htaccess 部分是为了让 fetch 工作,所以它会路由到
/start,但现在/start在我的服务器上返回 404托管。
标签: javascript reactjs .htaccess