问题
I want all of the following rewrites to be possible:
https://website.com/CAT/api/translation/tasks/get/3/4x
https://website.com/CAT/api/translation/tasks/get.php?param1=3¶m2=4x
https://website.com/CAT/api/glossary/folder/anotherfolder/put/6
https://website.com/CAT/api/glossary/folder/anotherfolder/put.php?param1=6
The first url works fine. However, I want the amount of parameters to be optional. If I remove a parameter: https://website.com/CAT/api/translation/tasks/get/3/
I get the error The requested URL /CAT/api.php was not found on this server.
For some reason, only having 1 parameter causes the rewrite to change the folder api to api.php instead of the file get to get.php.
Here is my .htaccess which is located in the CAT directory.
Options -MultiViews
RewriteEngine On
RewriteBase /CAT/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/([^/]+)/([^/]+)/?$ $1.php?param1=$2¶m2=$3 [QSA,NC,L]
来源:https://stackoverflow.com/questions/60230378/how-do-i-make-parameters-optional-in-my-htaccess-rewrite