1

I'm trying to get my .htaccess file to work with PHPDesktop, but .htaccess doesn't seem to work. I saw that it's possible to hide specific files in the settings.json file, but it seems pretty limited. Is there a way to use my .htaccess file instead of using the settings.json file? Here's what I use for my .htaccess file:

RewriteEngine On
RewriteRule ^public/(.+) public/$1 [END] # allow direct access on public folder
RewriteRule ^ index.php [END]            # anything else will be directed to index.php
AmirBll
  • 1,081
  • 1
  • 13
  • 25
noClue
  • 958
  • 1
  • 13
  • 34

1 Answers1

2

No, you can't use .htaccess with PHP Desktop. PHP Desktop embeds a Mongoose web server which doesn't support such configuration file.

The rewrite rules from your .htaccess can be handled by setting web_server > 404_handler in settings.json file to /index.php.

Czarek Tomczak
  • 20,079
  • 5
  • 49
  • 56
  • Seems like a simple solution, but what about files that exist? The reason I have this .htaccess is to make use of a router, so everything (with the exception of the public folder, which has css, javascript and images) goes through index.php. Your solution would only take care of non-existent files. – noClue May 07 '19 at 20:45
  • @noClue PHP Desktop provides only basic support for rewrite rules to handle 404 requests. You have control over files and requests, so you should be able to resolve any issues that you have. – Czarek Tomczak May 08 '19 at 12:04
  • So I solved my issue by defining a constant variable in index.php, which is the only php file you should be allowed to access directly: `define("accessible", TRUE);`. Then, in any of the php files I don't want to be accessed directly, I just add this: `if(!defined("accessible")) { header("Location: ../"); die(); }`. Works perfectly, along with the `web_server > 404_handler` setting in the settings.json file. Thanks! – noClue May 21 '19 at 03:13