bcosca / fatfree

A powerful yet easy-to-use PHP micro-framework designed to help you build dynamic and robust Web applications - fast!

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

webcoder31 opened this issue · comments

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

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?

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

@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 ;)

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.

commented

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

@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]
commented

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

@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 ;)

@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

Ok thanks for reporting back.