Move my project from public_html/web to public_html I have a Drupal site installed via composer, creating a structure like

vendor/
config/
composer.json
etc/
web/core
web/themes
web/index.php
web/etc


Is there a way to change the web folder to a public_html folder so I can use it on my hosting? So the structure needs to be:

vendor/
config/
composer.json
etc/
public_html/core
public_html/themes
public_html/index.php
public_html/etc


I got it working now by using .htaccess but I started using this method with the config outside of my root folder because of the security advantages. With this method, the config is still in my root but via htaccess I point everybody to the web folder. Is this still secure enough?

So how can I change this and is it necessary?
You should be able to change the installer paths in composer.json, which defines where the files are placed:

"installer-paths": {
  "web/core": ["type:drupal-core"],
  "web/modules/contrib/{$name}": ["type:drupal-module"],
  "web/profiles/contrib/{$name}": ["type:drupal-profile"],
  "web/themes/contrib/{$name}": ["type:drupal-theme"],
  "drush/contrib/{$name}": ["type:drupal-drush"]
},


to:

"installer-paths": {
  "public_html/core": ["type:drupal-core"],
  "public_html/modules/contrib/{$name}": ["type:drupal-module"],
  "public_html/profiles/contrib/{$name}": ["type:drupal-profile"],
  "public_html/themes/contrib/{$name}": ["type:drupal-theme"],
  "drush/contrib/{$name}": ["type:drupal-drush"]
},


You can then rename the web folder to public_html and everything should work.