Help with the proper routes

chrystman
Member | 7
+
0
-

Hi, i need help to properly setup my routes, my index.php file is located /public so if a user visits my site site becomes example.com/public but i am finding it very difficult to route to other pages for instance if a user want to go to the login i want my site to be viewed as example.com/login, i want to know to do this.
Thanks

dakur
Member | 493
+
+1
-

Hi @chrystman,

just set DocumentRoot in Apache (or whatever webserver you use) to public folder and then you can use router in normal way.

chrystman
Member | 7
+
0
-

dakur wrote:

Hi @chrystman,

just set DocumentRoot in Apache (or whatever webserver you use) to public folder and then you can use router in normal way.

Thanks @dakur, I am already using public folder without any problem but i do want to show public in the url when a user navigates to other pages.
what i mean is i want public only to be visible in the landing page/example.com/public
but when a goes the login page and other pages i what the url to be example.com/login, example.com/terms
what's what i am talking about.
I hope you understand's me.
Thank once again.

dakur
Member | 493
+
0
-

@chrystman No no, I'm talking about document root which is where you're public web files (e.g. index.php) are located on the webserver's filesystem. This has nothing to do with routes. If you have your web e.g. at /var/www/myweb on the disc and you follow standard Nette directory structure (which I recommend for security reasons), then index.php sits inside of www/ (or maybe public/ in your case?) subfolder and your document root is /var/www/myweb/www (or /var/www/myweb/public). As the result, when you come to yourdomain.com, you will see your www/index.php.

The thing you are talking about are routes, which is a step further. It's a mapping from URL to presenters. Having all of your code in one index.php would be awfully chaotic so presenters are logical subunits which you can split your code into (e.g. login, homepage, newsletter, articles etc.). To know to which presenter should the request be directed, there is a param in URL (index.php?presenter=Homepage) and SimpleRouter makes it work.

But as the URL is still awful, the router mapping also offers aliases (aka nice SEO URL) where you can instruct that /homepage will go to index.php?presenter=Homepage, /login to index.php?presenter=Login etc. See Route collection. That's where you define your /terms, /login etc.

Last edited by dakur (2022-04-20 07:44)