bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!
2.66k stars 446 forks source link

Using JIG record's ids in URLs leads to a 404 error returned by Apache server #1181

Closed webcoder31 closed 4 years ago

webcoder31 commented 4 years ago

Hi,

I would like to use JIG record IDs to identify server resources in my URLs. But this is problematic in terms of URL rewriting because JIG record IDs contains a period (dot character).

For example, an XHR POST request to /api/users/5e49c2c9006e01.57979156 leads to a 404 error returned by an Apache server with an htaccess file defining the following "out of the box" basic rule:

RewriteCond% {REQUEST_FILENAME}! -L
RewriteCond% {REQUEST_FILENAME}! -F
RewriteCond% {REQUEST_FILENAME}! -D
RewriteRule. * Index.php [L, QSA]
RewriteRule. * - [E = HTTP_AUTHORIZATION:% {HTTP: Authorization}, L]

I searched a lot on stackoverflow etc. and tried a lot of tricks too, but I can't find anything helping me to solve this problem.

Does anyone could provide help or trick facing this issue?

Thanks in advance

xfra35 commented 4 years ago

The period character shouldn't be an issue.

Are you sure the rewriting is effective? Have you tried passing a basic string with only letters, such as /api/users/test?

geniuswebtools commented 4 years ago

RewriteRule. * Index.php [L, QSA] <-- Capital I?

webcoder31 commented 4 years ago

@xfra35 Yes, I tried it and it works. For now, replacing dot with underscore and doing the inverse to retrieve the real JIG ID is the workaround I use to bypass the issue. I know the problem is not directly related to F3 but to Apache. So, many thanks for the support ;)

@geniuswebtools Just a typo when typing the example in the post. I use index.php in my htaccess file ;)

xfra35 commented 4 years ago

Just a random guess: have you tried disabling Multiviews in .htaccess?

Options -Multiviews

I once had issues related to periods because of that option, although your issue is different here.

KOTRET commented 4 years ago

is the dot directly after RewriteRule intended? That should be RewriteRule .*… (space followed by .* instead of dot, space asterisk)

webcoder31 commented 4 years ago

@xfra35 Disabling Multiviews did not change anything...

@KOTRET This is a typo due to cut'n'paste via G...gle translator :( Here is my reel htaccess file:

RewriteEngine On

RewriteRule ^(tmp)\/|\.ini$ - [R=404]

RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L,QSA]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
KOTRET commented 4 years ago

Does the routing work in general? is the index.php triggered or is it an error caused by apache?

webcoder31 commented 4 years ago

@KOTRET Hello Chris, Yes, the routing works fine with "dot-less" urls. And no, index.php is not triggered. The 404 error page is issued by the HTTP server. I will investigate to this direction because I guess that the issue is due to my environment; F3 work well. I will let you know if I find something relevant that may matter to F3. Anyway, I'm still thinking using a period (or any other character that may be significant in urls) in server resources identifiers is not a judicious choice; using an hyphen would have been more advised. Even better, using letters and numbers only, since IDs do not generally serve any other goal than identifying. I guess that the fact of using special chars in the ID is to distinguish several information that probably matter at some point. So I'm a bit curious to know what they are representing and what they are intended for ? Thank you very much for your support. And best regards to all the F3 team ;)

webcoder31 commented 4 years ago

@KOTRET Hello Chris, The issue is due to my dev stack. I use gulp task-runner and the php-connect plugin to serve my app. In fact, php-connect does not care about htaccess (thing I was not aware and did not suspect because all was working as if it does). Simply, it directly route all requests to index.php excepted when the requested url contain a dot. In this case, I guess it try to find a corresponding file in the file system and return a 404 error if none matches. So I'm confused to made people helped me wasting time with this issue. Thank very much to all for your support. Best regards

xfra35 commented 4 years ago

Ok thanks for reporting back.