E
E
Eugene2018-02-27 10:54:24
PHP
Eugene, 2018-02-27 10:54:24

How to return .php at the end of page address?

Hello!
Please tell me how to return the file extension at the end of the address.
Site with one entry point.
Now it removes the file extension in the address bar.
The index file looks like this

<?
$params = array();
$query_string = str_replace("page=","",trim($_SERVER['QUERY_STRING']));
$query_string = urldecode($query_string);
$query_params = explode("/",$query_string);
foreach ($query_params as $query_param)
  if ($query_param != "")
    $params[] = mysql_escape_string($query_param);
?>
<?	
if (count($params) == 0) $params[0] = "main";
  require_once file_exists('modules/' . $params[0] . '.php')
  ? 'modules/' . $params[0] . '.php' : 'modules/404.php'; 
?>

.htaccess looks like this
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L]
AddDefaultCharset utf-8
AddType 'text/html; charset=utf-8' .html .htm .shtml
AddHandler application/x-httpd-php .html .htm .js

somehow I managed to win in an old project... but now I've tried everything, I can't do it...

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
Nurlan, 2018-02-27
@daager

Here: Send any request as a parameter. Remove:RewriteRule ^(.*)$ index.php?page=$1 [L]

RewriteEngine On #включить mod_rewrite
RewriteBase / #базовый url
RewriteCond %{REQUEST_FILENAME} !-f  #все <b>существующие</b> файлы не будут обрабатываться регуляркой
RewriteCond %{REQUEST_FILENAME} !-d #все <b>существующие</b> папки не будут обрабатываться регуляркой
RewriteRule ^(.*)$ index.php?page=$1 [L] #перенаправляем то, что подходит под регулярку в виде GET-параметра

But PHP code will break and is unsafe, because connecting anything by url is so-so.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question