我找了又找,问过了,没有joy.

布卢夫: 在我使用Bluehost ApacheWordPress作为后端的Reaction Headless CMS上,当我刷新一个不是根目录的页面时,我得到了一个页面找不到错误.

我已try 将htaccess文件修改为.html,而不是.php 这里有两个问题:

  1. 对我的自定义终结点的任何请求都不再起作用
  2. 如果我在wp-admin上保存固定链接,则htaccess文件将恢复为.php

当.htaccess文件为.php时,My Site使用定制REST API工作得很好,但重新加载除根目录以外的任何页面都会导致页面未找到错误.

如果有帮助的话,我正在我的Reaction应用程序上使用BrowserRouter.

先谢谢你.

我已经将我的.htaccess文件修改为.index,而不是没有joy的.php

HTAccess内容:

# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_expires.c>
    ExpiresActive On
    ExpiresByType image/jpg "access plus 1 hour"
    ExpiresByType image/jpeg "access plus 1 hour"
    ExpiresByType image/gif "access plus 1 hour"
    ExpiresByType image/png "access plus 1 hour"
    ExpiresByType text/css "access plus 1 hour"
    ExpiresByType application/pdf "access plus 6 hours"
    ExpiresByType text/javascript "access plus 1 hour"
    ExpiresByType text/html "access plus 0 seconds"
    ExpiresByType image/x-icon "access plus 1 year"
    ExpiresDefault "access plus 5 minutes"
</IfModule>
Options -Indexes
<IfModule mod_headers.c>
    Header set X-Endurance-Cache-Level "1"
    Header set X-nginx-cache "WordPress"
</IfModule>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
AddHandler application/x-httpd-ea-php82___lsphp .php

# BEGIN LiteSpeed
# The directives (lines) between "BEGIN LiteSpeed" and "END LiteSpeed" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule Litespeed>
SetEnv noabort 1
</IfModule>
# END LiteSpeed

# php -- BEGIN cPanel-generated handler, do not edit
# Set the “ea-php81” package as the default “PHP” programming language.
<IfModule mime_module>
  AddHandler application/x-httpd-ea-php81___lsphp .php .php8 .phtml
</IfModule>
# php -- END cPanel-generated handler, do not edit


#My custom code


#End my custom code

IMtry 到达的示例路由是home epage.com/wp-json/myapp/v1/end

推荐答案

IMtry 到达的示例路由是home epage.com/wp-json/myapp/v1/end

假设从/wp-json/...开始的每个请求都应该通过WordPress(index.php)发送,而其他所有内容都发送到您的Reaction前端(index.html),那么您可以在.htaccess文件的顶部添加类似以下内容的内容,before# BEGIN WordPress注释标记(这样以后就不会被WP本身覆盖).

# Allow requests for the homepage (root dir) to be handled by index.html (not WordPress)
# (Prioritise index.html over index.php)
DirectoryIndex index.html index.php

# Route all requests except for "/wp-json/..." to index.html
# (Also excludes requests for physical files and directories)
RewriteRule ^index\.(php|html)$ - [L]
RewriteCond %{REQUEST_URI} !^/wp-json/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]

# BEGIN WordPress
:

CondPattern !^/wp-json/确保仅当REQUEST_URI服务器变量(根相对URL路径)not/wp-json/开头时才处理规则.

您不需要重复RewriteEngine On指令,这在后面的WordPress代码块中已经出现了.实际上,"获胜"并控制整个文件的正是该指令的last个实例.

Reactjs相关问答推荐

Shadck/ui Select -当用户 Select 项目时更改状态

如何通过浏览器路由在单独的.jsx文件中使用MUI抽屉?

cypress 不能点击SPAN

如何在重新图表中更改悬停时的条形填充 colored颜色 ?

在Reaction中单击并显示子组件延迟/动画

在动态React组件中删除事件侦听器

通过createRoot创建的React元素无法调用Provider值

console.logs 没有显示在浏览器控制台上,但显示在我的终端上

如何更新 FunctionComponentElement 的 props

无法从子组件传递数据到父组件

React - 将一个充满空值的无限大小的数组存储在 ref 中是否可以,或者我应该重置数组吗?

损坏的图像 React useState

React Native Realm 应用程序在发布构建后崩溃

React Native PermissionsAndroid 不包括 READ_MEDIA_IMAGES.如何解决这个问题?

从输入中获取数字时,react 计数器不会增加

React如何在用户登录后等待当前用户数据被获取

react 路由路由加载器不适用于嵌套组件

如何在 react-router-dom v6 中实现监听功能?

点击提交后自动添加#

material uireact ,如何从表格中删除阴影?试图找到 api 但找不到正确的属性