I making a little CMS, but I dont like these links, for example, example.com/page.php
. I want to make a something like this example.com/page
with the same file. I know I can make a new directory and put a index.php file, but, if I have 20 pages, then I need new 20 directories, and that's not a solution.
Asked
Active
Viewed 54 times
0

eatmailyo
- 670
- 1
- 12
- 33
-
What you are searching for is called a router, there is a lot of implementations in all frameworks, yu can do it with plain php, use this http://php.net/manual/fr/class.yaf-router.php for instance, but you can also search for php routers, a thousand of implementations are available on the internet – D. Peter May 31 '17 at 19:21
-
@D.Peter Thank you, but I don't know, how to use it, can you please help me? – eatmailyo May 31 '17 at 19:33
-
It depends on your webserver, wich one are you using ? apache, nginx, lighttpd, another ? – D. Peter May 31 '17 at 19:35
-
@D.Peter Im using nginx – eatmailyo May 31 '17 at 19:41
-
you have to rewrite your routes, such as here : https://stackoverflow.com/questions/12924896/rewrite-all-requests-to-index-php-with-nginx routes are in the nginx_dir/conf/nginx.conf but if it is too complicated, and if you don't want a dependance of the server, You can use a framework such as Silex or Sympony, or whatever, wich are providing a routing easiest with teh possibility to change you backend server easily. you can however use a simple router such as https://github.com/dannyvankooten/PHP-Router (take a look at Yaml router on at the end of the page) – D. Peter May 31 '17 at 19:57
1 Answers
0
I found a answer for my problem
In .htaccess file need to add RewriteRule
Options +FollowSymlinks
Options -MultiViews
RewriteEngine ON
RewriteRule ^page$ /page.php [L]
RewriteRule ^page2$ /page2.php [L]

eatmailyo
- 670
- 1
- 12
- 33