【问题标题】:Need help to fix my .htaccess file需要帮助来修复我的 .htaccess 文件
【发布时间】:2017-07-01 14:47:43
【问题描述】:

我的 index.php 文件位于:

myserverHost/api/public/

其中包括获取令牌之类的 api 调用。喜欢:

myserverHost/api/public/token

只有当我输入准确的 URL 时它才有效。即

myserverHost/api/public/token

我正在尝试编写我可以使用的重写规则:

myserverHost/api/token

这是我在 .htaccess 文件内容中尝试过的内容:

RewriteEngine On
#RewriteBase /api/

RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

# Make sure $HTTP_RAW_POST_DATA is deprecated warning does not appear
#php_value   always_populate_raw_post_data   -1

【问题讨论】:

  • 抱歉,我没有看到任何尝试对您发布的配置文件中的要求进行编码。
  • 亲爱的,我是这个话题的新手。我已经提到了我的代码尝试
  • 您不应该只是更改部署,使DocumentRootpublic 吗?还是您希望在某些情况下显示public
  • 我不想公开显示在我的网址中。而不是 myserverHost/api/public/token 我想使用 myserverHost/api/token。

标签: apache .htaccess mod-rewrite url-rewriting


【解决方案1】:

试试这个,这将删除格式为 public/x -> X

的 public
RewriteEngine On
#RewriteBase /api/

RewriteRule .* - [env=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ public/$1 [L]
RewriteRule ^ index.php [QSA,L]

【讨论】:

  • 我收到Not Found The requested URL /api/token was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
  • 我的 .htaccess 文件位于 /api/public 目录
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-04-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-07-19
  • 1970-01-01
相关资源
最近更新 更多