Page 1 of 1

No trailing slash on URLs , no Redirects!

PostPosted: 12. July 2021 21:07
by markosjal
I am looking to reproduce the behavior I got with the PHP development server which allowed me to load for example
Code: Select all
http://myserver/directory

and get
Code: Select all
http://myserver/directory/index.php


I need to do this without redirects.
The only way I have found to do this so far is with .htaccess. All other solutions seem to produce a redirect!

My .htaccess is now is as follows:

Code: Select all
DirectorySlash Off

RewriteEngine On
RewriteRule ^eSCL/ScannerStatus/?$ eSCL/ScannerStatus/index.php [L]
RewriteRule ^eSCL/ScannerCapabilities/?$ eSCL/ScannerCapabilities/index.php [L]
RewriteRule ^eSCL/ScanJobs/?$ eSCL/ScanJobs/index.php [L]
RewriteRule ^eSCL/Scans/?$ eSCL/Scans/index.php [L]
RewriteRule ^eSCL/Scans/NextDocument/?$ eSCL/Scans/NextDocument/index.php [L]
# RewriteRule ^eSCL/ScanJobs/.*/?$ eSCL/ScanJobs/.*/index.php [L]
# RewriteRule ^eSCL/ScanJobs/.*/.*/?$ eSCL/ScanJobs/.*/.*/index.php [L]

this works fine except the last two commented lines. You see I have some directories that are generated randomly with UUIDS
they look like this:
Code: Select all
/eSCL/ScanJobs/267d04d6-70dc-4693-8d96-063391ec4066

I need to access this like this
Code: Select all
/eSCL/ScanJobs/267d04d6-70dc-4693-8d96-063391ec4066

and get the index.php contained in the directory named by UUID . THESE ARE RANDOM UUIDS! I need a wildcard solution.
I also have:
Code: Select all
/eSCL/ScanJobs/267d04d6-70dc-4693-8d96-063391ec4066/NextDocument

Which here again I want to get the index.php there the "NextDocument" folder. The "NextDocument" is a fixed name but the UUID wildcard remains.

Any help on this?

Re: No trailing slash on URLs , no Redirects!

PostPosted: 12. July 2021 23:03
by Nobbie
Actually you are doing plain nonsense. Simply read the Apache Doc about DirectoryIndex, which does the job.

Re: No trailing slash on URLs , no Redirects!

PostPosted: 12. July 2021 23:18
by markosjal
If you mean "DirectoryIndex Directive" this is what the docs say but note again the trailing slash. It does not apply to URLs without trailing slash!

https://httpd.apache.org/docs/2.4/mod/mod_dir.html

So please tell me why you claim I am asking "nonsense"?

Nonsense seems to be your reply as that behavior explained in DirectoryIndex Directive is exactly the behavior I am getting already as long as the trailing slash is used. I need that behavior WITHOUT trailing slash.

Do you get points for posts regardless of them being nonsense? Maybe you like to "look" like an expert because you have so many posts regardless of the nonsense contained in them?

If your knowledge were worth anything you would have explained said use of the directive. Instead you elude to a vague "answer" that does not take the question into account.

Re: No trailing slash on URLs , no Redirects!

PostPosted: 13. July 2021 08:13
by Altrea
DirectoryIndex works without trailing slashes because DirectorySlash adds the trailing slash. But to do so it fires a HTTP status 301 redirect.

Thats why DirectorySlash is set to off here. the requirement was: no redirects.
There are some reasons to do so in unattended environments like scheduled tasks or apis.

Re: No trailing slash on URLs , no Redirects!

PostPosted: 14. July 2021 12:11
by Nobbie
Code: Select all
RewriteEngine On
RewriteRule ^(.*[^/])$ $1/index.php [L]


Should do it for all cases.