v2024
got Bad Request - Invalid URL then i try to get file in list or view page
but if i try to get existing file in edit page file is opening
OpenPanel on the local computer everything works.
After transferring to IIS, the links stop working.Bad Request - Invalid URL
HTTP Error 400. The request URL is invalid.
if you disable “Encrypt File Path”
everything works everywhere.
debug enabled
in /log folder nothingif the file name consists of letters (scan.pdf) of the English alphabet, then the file is opened.
if filename conains russian symbols got error “HTTP Error 400. The request URL is invalid.”
if you disable “Encrypt File Path” everything works everywhere.
That probably means the encryption/decryption does not work the same on your IIS web server.
Make sure you use the same PHP version as your local PC, and make sure PHP ext-hash, ext-mbstring, and ext-openssl are enabled for the PHP of the IIS. You may use phpinfo() to check the PHP on your IIS server.You should enable Debug (just follow the instruction in the docs) to check the detailed error message in the log file.Make sure logging is properly set up so you can debug. Also make sure you have enabled error_reporting and display_errors in the php.ini (for your IIS) during debugging.
Note that if you have enabled “production” for Environment setting, you should set it back to “development” during debugging, you can modify the setting in the src\config.php manually to “ENVIRONMENT” => “development”.Another possibilitiy is that the non-alphanumerical file name are not saved properly. Make sure everything supports utf-8, including (but not limited to):
The charset of the project is utf-8,
The database/table/field supports utf-8. If MySQL, use utf8bm4. If MSSQL, use nvarchar, not varchar.
Export the table data to a utf-8 file and check if the russian characters in the file names are saved properly.
Are you sure the file with russian characters in file name are correctly uploaded on your IIS server? If the file name stored in the database does not match the actual physical file name, it won’t work.
You may write some code in a page (you need to use the PHPMaker config and functions) to test what could not be decrypted successfully, e.g.
echo Decrypt(Encrypt("Your russian characters"));
echo Decrypt($sessionId); // where $sessionId is the "session" parameter in above URL
echo Decrypt($fn, $sessionId . Config("ENCRYPTION_KEY")); // where $fn is the encrypted string after "contract/" and before "?".
The file name cannot be decrypted. What is your Config(“ENCRYPTION_KEY”)? You can find it in src/config.php.
Make sure it is not empty. If you see the error “Error: Missing encryption key. Please click Tools → Advanced Settings and set ‘Encryption key’.” during generation, do not ignore it. Follow the instruction to set it.Session depends on cookie. Double check your cookie settings in advanced settings. If you enable Cookie Secure, make sure your site uses HTTPS, not HTTP. If you set Cookie SameSite as “None”, you must enable Cookie Secure.
So it seems that the session has been changed. You may compare the session id (i.e. session_id()) of the page and the decrypted session id (i.e. Decrypt($sessionId)) in the URL.
So session_id() equals Decrypt($sessionId). Everything is correct. The only explanation might be what you didn’t show so far, the Russian characters, although you said you can encrypt/decrypt correctly. You may post an example for testing as follows:
Export your table to a .sql file (with CREATE TABLE statement)
Delete all records (INSERT statements) except one (INSERT statement) for testing. The record should contains the file name with Russian characters.
The problem is not related to PHP or Russian characters, it is due to IIS settings for the URL, when the file name is long, the URL with encrypted file path is too long for IIS with default settings, you may read the follows:
Http.sys registry settings for Windows, note that:
Changes that are made to the registry will not take effect until you restart the HTTP service. Additionally, you may have to restart any related IIS services.
See the last section of above article.
You need to increase at least the UrlSegmentMaxLength registry setting.
Thanks s lot!
I think this will be useful to many, please add it to the FAQ or installation instructions.PowerShell script:
Set-ItemProperty -Path HKLM:\System\CurrentControlSet\Services\HTTP\Parameters -Name UrlSegmentMaxLength -Value 2000 -Type “Dword”