简体   繁体   English

.htaccess 在 XAMPP 本地主机上工作,但不在虚拟主机上

[英].htaccess working on XAMPP localhost but not on Webhosting

Hei guys, for my webpage I wanted to implement some simple REST-Services to serve some Json.嘿伙计们,对于我的网页,我想实现一些简单的 REST 服务来服务一些 Json。

To achieve that I created subfolder api and in this folder I created index.php and .htaccess file.为此,我创建了子文件夹 api 并在此文件夹中创建了 index.php 和 .htaccess 文件。

index.php uses AltoRouter to handle Routes called on /api. index.php 使用 AltoRouter 处理在 /api 上调用的路由。

.htaccess locks like following: .htaccess 锁定如下:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]

mod_rewrite is enable on my webhoster. mod_rewrite 在我的虚拟主机上启用。 (I was abelt to test this using some simple examples served by the webhoster) (我很乐意使用 webhoster 提供的一些简单示例对此进行测试)

I tested everthing on my local computer using localhost xampp.我使用 localhost xampp 在本地计算机上测试了所有内容。 Everthing is working fine.一切正常。 (GET and POST Requests) (GET 和 POST 请求)

After uploading this to my webpage I figured out, that POST Requests are Redirected to GET and therefore are not working.将此上传到我的网页后,我发现 POST 请求被重定向到 GET,因此无法正常工作。

Can anybody help with that issue.任何人都可以帮助解决这个问题。 I need this POST Requests to be redirected to my index.php and be handled there to make some data update on my webpage.我需要将此 POST 请求重定向到我的 index.php 并在那里处理以在我的网页上进行一些数据更新。

Regards Manuel问候曼努埃尔

There is an update: My Webhoster seams to use a nginx proxy that redirects to Apache.有一个更新:我的 Webhoster 接缝使用重定向到 Apache 的 nginx 代理。 POST seams to get coverted to GET and therefore my mechanism is not working anymore. POST 接缝被隐藏为 GET,因此我的机制不再起作用。 Can anyone tell me how to force nginx to redirect POST as POST?谁能告诉我如何强制 nginx 将 POST 重定向为 POST?

Manuel曼努埃尔

You can include the PHP file in your /api folder in your PHP file in your Root folder.您可以在根文件夹中的 PHP 文件的 /api 文件夹中包含 PHP 文件。

Just add the line include "./api/index.php" to your PHP in the Root folder.只需将行include "./api/index.php"添加到根文件夹中的 PHP 即可。

Then the functions work in the PHP file in the /api folder, without having to open that specific PHP file in the /api folder.然后这些函数在 /api 文件夹中的 PHP 文件中工作,而无需打开 /api 文件夹中的特定 PHP 文件。

https://www.php.net/manual/en/function.include.php https://www.php.net/manual/en/function.include.php

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM