V
V
vankivol2017-05-30 17:18:57
PHP
vankivol, 2017-05-30 17:18:57

Mod_rewrite and PHP. How to make a single entry point?

Ran into a problem while writing a single entry point with Mod_rewrite and PHP.
.htaccess code

AddDefaultCharset UTF-8
Options -Indexes
Options +FollowSymlinks

RewriteEngine on
 
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule  ^([a-zA-Z0-9_-]+)$ index.php?route=$1 [QSA,L]

In PHP we get data through The problem is that if there is a file in the directory with the same name as the GET Parameter received via .htaccess, then the GET Parameter is empty. For example: There is a link domain_name/contacts If there is a contacts.php file in the GET directory, the route parameter passed through .htaccess will be empty. How to be in this situation? Am I doing something wrong or is there a way to fix this problem? Thank you.
$route=$_GET["route"];

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
McBernar, 2017-05-30
@McBernar

The meaning of the front controller is precisely that you do not have a contacts.php file, but have classes, objects and methods that are loaded depending on the route.

V
Viktor Taran, 2017-05-30
@shambler81

RewriteRule  ^([a-zA-Z0-9_-]+)$ index.php\?route=$1 [QSA,L]

And who will screen for you?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question