htaccess 文件 - 如何重定向到某个 link 而不是网站?

htaccess File - How to redirect to a certain link but not to website?

假设我有 http://example.com 作为我的网站。

现在,当我执行 http://example.com/api/login 时,登录脚本有效。

但是当我执行 http://example.com 时,它会直接进入我的路由器设置中的默认开关,因为 htaccess 文件中的 index.php 显示 echos Access Denied。 在这两种情况下都不会显示网站。

所有文件都在 public_html 文件夹中用于托管。

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]

那是我当前的 htaccess 文件。我该怎么做才能解决这个问题?

您的基本文件夹的内容是什么?默认情况下 php 将始终打开 index.php 文件,如果您想前往登录页面而不是 http://example.com/api/login 然后编辑您的 index.php 文件以重定向到它

  die(header("location: http://example.com/api/login"));

放在index.php脚本的顶部

我通过在 public_html 中创建一个名为 backend 的新文件夹来修复它 我将 htaccess 更改为

RewriteEngine On
RewriteBase /backend/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php [QSA,L]

我把所有与后端相关的东西放在那里,现在可以使用了