Routing with Periods / Dots / Full-Stops (.)

farhanianz
Member | 8
+
0
-

Hello there! Just registered here..

This is Farhan from Bangladesh. I've started using Nette framework 3.* since a few days ago. I knew about the framework for a long ago perhaps I was waiting for the 3.* release.

So, this is my actually my first attempt of using the framework. One sentence for now: Thanks for the nice & clean framework with a great amount of possibilities.


Anyway, here's where I'm stuck. I'm allowing users to use dots(.) in their username, so while visiting the profile page I found that it's not actually working. I need to be able to accept periods/full-stops/dots in URI but it turns out saying:

	Not Found
	The requested resource /user/test.dot was not found on this server.

Expected Behavior:

  • User not found? Show 404 page
  • Found? Render the template.

So far I've tried these things-

1. Added regex in the RouterFactory to validate the URI

	$router->addRoute('user/<username [a-zA-Z0-9\._]+>', 'User:viewProfile');

Result: same as before.

2. Modified the .htaccess a little just to check if it's working

	# Skip existing files
	RewriteCond %{REQUEST_FILENAME} -f
	RewriteRule index.php - [QSA,L,C]
	RewriteRule .* - [QSA,L]

	# Front controller
	RewriteCond %{REQUEST_FILENAME} !-f
	RewriteCond %{REQUEST_FILENAME} !-d
	RewriteRule ^(.*)$ index.php [QSA,L]

Result: Same as before.

3. Combined the above two
Result: Same as before.

P.S: Using nette/sandbox & project created through composer.

Any help would be much appreciated.

Last edited by farhanianz (2020-05-30 13:23)

CZechBoY
Member | 3608
+
+1
-

The error is from Apache or Nette?

David Grudl
Nette Core | 8218
+
+1
-

This is Apache configuration problem. It probably thinks test.dot is a file and returns this error.

The Skip existing files section seems suspicious to me, but I don't know.

farhanianz
Member | 8
+
0
-

CZechBoY wrote:

The error is from Apache or Nette?

David Grudl wrote:

This is Apache configuration problem. It probably thinks test.dot is a file and returns this error.
The Skip existing files section seems suspicious to me, but I don't know.

I was running the server by sending this command, just after creating the project by using composer, it was documented (& yeah quite usual to say so) in nette/sandbox repo.

php -S localhost:8000 -t www

Well, I just figured out as you just mentioned the word “Apache”. So, started the server from Xampp, it is working as expected.


An additional note for people who just fall into the same problem:

You can't actually see the project folder on Xampp/Apache server because it contains a .htaccess (your-project/.htaccess) file which contains the following line: I think it should be there for security purposes.

	Require all denied

I'm not talking about your-project/www/.htaccess, neither you can access it by entering the directory name, unless you browse directly to the your-project/www directory. I mean you'll have to directly point the URI to: http://localhost/your-project/www

Thank you David Grudl & CzechBoY.