FAQ - How to use a .htaccess to set your own redirect on your instance

DoliCloud is an open hosting solution. This means that, you can view, modify and download the program and data files. You can also edit files on your instances. Among this files, you can edit .htaccess files that are special files to allow you to define redirection directive on some Urls.





Create localy a .htaccess file


If you want to set a .htaccess file, the first step is to create it locally with any text editor (the name can't be modified).

Fill its content with a content to define the redirections you want to set. For example, for a .htaccess file to store into the .well-known directory of your instance:

RewriteEngine On
RewriteEngine ^oauth-authorization-server(/.*)?$  /custom/mymodule/oauth/mymoduleoauth.php [PT,L]
RewriteEngine ^openid-configuration(/.*)?$  /custom/mymodule/oauth/mymoduleopenid.php [PT,L]
RewriteEngine ^oauth-protected-resource(/.*)?$  /custom/mymodule/oauth/mymoduleoauthprotectedresource.php [PT,L]


Restriction on the use of .htaccess file


For security and performance reason, usage of a .htaccess is enabled only on the directory .well-known at the root of your instance.
If your need to set a .htaccess for another directory, you need to contact us from your customer dashboard, menu Support - Contact us, to ask us to enable the use of .htaccess on a larger surface of your instance.



Transfer the .htaccess files on your instance


To be able to transfer local files on your instance, you must use a file browser navigator that can connect to your instance using the SFTP protocol. Any SFTP software can be used for that. Take a look at the FAQ on how to use a SFTP client software to access files of your instance.

Use your SFTP client software to transfer the .htaccess file you built into the target directory matching the url where you need the redirection to work. You can set it into the root directory of your instance (usually the htdocs directory) but placing it into a given directory reduce the risk of unexpected side effect on the rest of your application.
For example, the .htaccess file defined into the example is provided to be placed into the directoy .well-known in htdocs (you can create the repository with your SFTP software if you don't have it).

Warning: Files and directories on your instances are in read-only mode by default, you must use the feature of your SFTP software to first set the permissions, on the files to replace, or the directories to write into, to set the file or directory in "Write allowed"mode.
Usually you can do this with a right click on the file from your SFTP client software. Then you will be able to overwrite the files with your own version of files.

 

 

 

FAQ written by the DoliCloud support team.