T
T
trall2013-11-24 10:15:05
PHP
trall, 2013-11-24 10:15:05

How to turn /help.php?page=somePage link into /help/somePage? (apache mod_rewrite)?

There is a simple PHP code that takes files from a folder and displays them:

<?php
error_reporting(0);
$page = $_GET['page'];
if (file_exists('help-pages/'.$page.'.php')) {
  include('help-pages/'.$page.'.php');
} else {
  echo "not found";
}
?>

It is necessary to make the /help.php?page=somePage links turn into /help/somePage with special magic (there may be something else instead of somePage). How? I looked at a lot of articles on mod_rewrite, but understood little. Everything that I did myself does not work.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene Mosyukov, 2013-11-24
@sashablashenkov

In .htaccess:

RewriteEngine on
RewriteRule ^help/(.*)$ /help.php?page=$1

N
Nikita Gusakov, 2013-11-24
@hell0w0rd

Why do you need it? I never understood it.
Well, write $_SERVER['REQUEST_URI'] inside php and that's it, what's the problem?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question