Routing: How to prevent user from directly access content page without url rewrite?

routing address: /resources
actual file location: /include/resources.php

How to prevent user from directly access and only allow access via ?


I believe the .htaccess file is not viewable online so your routes should remain hidden.

When I look at the source code of one of my routed pages, I see no evidence of where the underlying file is located at, so if you have not made the path public, it should remain hidden.

If you are concerned about someone looking at your file structure and figuring out where your file is located at, I would recommend putting a blank index.html file in each folder, so the underlying files are not visible.

The above addresses how to hide the path of your file.

To address your question about reverse routing, I am not sure it is possible because right now you have it set up for:

/resources -> include/resources.php

If you set up an additional .htaccess rule to reverse redirect like this:

include/resouces.php -> /resources

It might create an infinite feedback loop. I have not tested it and just guessing based on the logic of it.

What if I create a variable in the main page with routing, and on the content page I create logic to redirect to ‘the main page with routing’ if the variable is false. That’s just a rough idea. Figuring out its feasibility and how to implement it.