Applicable to:
- Plesk for Linux
- Plesk for Windows
Question
How to change or reorder default index files (DirectoryIndex) for all websites on the server?
Answer
For Linux
Note: In the following example, index.php
is set as a priority. All newly created domains will have the new directoryIndex afterwards.
-
Connect to the server via SSH;
-
Add the following lines to
/usr/local/psa/admin/conf/panel.ini
using any text editor:CONFIG_TEXT: [webserver]
directoryIndex = "index.php index.html index.cgi index.pl index.xhtml index.htm index.shtml" -
Reconfigure all existing domains:
# plesk bin domain -l | while read i; do plesk repair web $i -y; done
For Windows
Note: In the following example test.php
file is set as a priority:
-
Connect to the server via RDP.
-
Open PowerShell command line
-
Run one of the following commands depending on the requirements:
-
Set up the "test.php" file as a default document file for all existing domains:
Note: change the "test.php" file in the command below to the correct one.
PS > plesk bin site -l | % { if ( $_ ) { &$env:windir\system32\inetsrv\appcmd.exe set config $_ /section:defaultDocument /enabled:true /+files.[value=`'test.php`'] } }
-
If the following error appears:
CONFIG_TEXT: ERROR ( message:New add object missing required attributes. Cannot add duplicate collection entry of type 'add' with unique key attribute 'value' set to 'main.php'. )
then such file is already present in the default documents list. Modify file priority manually in IIS > hostname > Sites > example.com > Default Documents.
-
Reset the customization of Default Documents to default for all domains:
PS > plesk bin site -l | % { if ( $_ ) { &$env:windir\system32\inetsrv\appcmd.exe clear config $_ /section:defaultDocument } }
-
Comments
10 comments
This is really helpful. I'd like to make some suggestions please:
For item 3, users who are not familiar with Event Handler may wonder which priority to use. Maybe it could be suggested that the default priority should be used.
For item 4, again new users may be confused. I would assume only the root user would have the correct permissions to run the "subscription" command. But if there is a better user to select, maybe you could add an appropriate suggestion?
Hi Just wondering how to I replace plesk default index page with our own index for all new domain or subdomain? please help if possible
Hi,
I tried the Linux solution but unfortunately it does not work on a new vhost.
event: domain created
priority: lowest
user: root
command: /home/admin/index-order.sh
I put this .sh file on the server itself on the same path.
But a new domain still has the html index up front insrtead of the php.
Is there a way to check in any logs if anything at all happened?
TIA
@Albert Stienen
What exact error do you see?
Please note that Powershell should be used and not the default Command Prompt.
Hello Russell H
Please, try this article: https://support.plesk.com/hc/en-us/articles/213367389
How do you do this for windows plesk?
Hello @Albert,
Thank you for paying our attention.
The article was reworked.
According to IIS documentation, there is no way to change the priority of existing file via command line. If it is necessary to change the priority of such a file, it should be configured manually in IIS > hostname > Sites > example.com > Default Documents.
A new file can be added to the top of the list using the following script:
plesk bin site -l | % { if ( $ ) { &$env:windir\system32\inetsrv\appcmd.exe set config $ /section:defaultDocument /enabled:true /+files.[value=`'test.php`'] } }
@Faris Hi!
Thank you for the feedback.
> For item 3, users who are not familiar with Event Handler may wonder which priority to use. Maybe it could be suggested that the default priority should be used.
Its hard to say for sure, how many handlers already exist and recommending to set the default (lowest) priority can lead to incorrect behavior.
> For item 4, again new users may be confused. I would assume only the root user would have the correct permissions to run the "subscription" command
I have updated the article according your recommendation. Thanks again :)
Hello @Wies,
Sorry for the late response.
I've tested the provided Linux solution for new domains and the solution worked fine for me.
Please, make sure you've followed all the steps as described.
The script location I used was /root/DefaultDoc.sh.
Also, I've noticed you've used a non-standard script name was it modified manually?
Generally, to make sure the script works as expected, start it manually after replacing "${NEW_DOMAIN_NAME}" with a real domain name.
@Steven A solution for Windows was added
Please sign in to leave a comment.