J
J
Jack Daniel's2016-02-08 14:03:22
PHP
Jack Daniel's, 2016-02-08 14:03:22

How to show pages with mod_rewrite?

htaccess contains:

RewriteEngine on
 RewriteRule ^([a-zA-Z0-9_-]+)$ urltest.php?post=$1

But the "problem" is that the page at the address, for example, site.ru/about is perceived as
site.ru/urltest.php?post=about
How to display the desired page? If any exception in mod_rewrite? Or you need to write something like:
<?php

 $page = $_GET['post'];

 if ($page === 'about') {
  require 'about.php';
 }else if ($page === 'main') {
  require 'main.php';
 }else {
  /*  и тд. и тп.*/
 }

?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Pavel, 2016-02-08
@Yea_intenet

httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rew...

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]

-f file presence
-d directory presence
!-f file absence
!-d directory absence
allow a request for a non-existent file: www.example.ru/dummydir will be parsed to www.example.ru/index.php?page=dummydir... (the get-request parameters will follow)
the same for the file

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question