Skip to content
Advertisement

URL Rewritting in htcaccess

I recently gone through a source code of php and found this code in .htaccess in root

JavaScript

Please,can someone explain me why it is written twice instead once?

Thanks.

Advertisement

Answer

If you look closely at those lines and compare them character-by-character you’ll notice that “doubled” lines actually not identical. I assume that, for example:

JavaScript

differ only by / character to take into account cases when one can query for users/some_user/ and users/someuser (with or without trailing slash). This is common thing to take into account, although it might be addressed at different levels – webserver or framework ones (or even both).

According to RegExp rules, putting a ? sign makes the preceding character optional, which allows you to replace those “duplicates” from above with e.g.:

JavaScript

which should be sufficient, but needs testing.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement