M
M
Maxim2012-05-15 10:07:53
PHP
Maxim, 2012-05-15 10:07:53

Need advice on creating the first page of the site

Good afternoon, everyone,

a rather noobish question has appeared, there is a small site, no CMS, only CSS / HTML inside there are some blocks in PHP, there are also not many pages, probably a maximum of 15. I would like to make it so that when clicking on links, something like site.ru/?page=price or site.ru/price is displayed .
I searched the Internet, I did not find an example understandable to my brain. I ask the community to direct me in the right direction, otherwise I feel that I am sitting inventing a bicycle.

Please don't scold me too much, I'm not a programmer at all, I've been familiar with PHP for just a couple of months.

Answer the question

In order to leave comments, you need to log in

8 answer(s)
A
Alexander, 2012-05-15
@disc

you need mod_rewrite

A
Andrey Burov, 2012-05-15
@BuriK666

To not rewrite anything in .htacces add

RewriteEngine on
RewriteBase /

RewriteRule ^price$ index.php?page=price

or:
RewriteEngine on
RewriteBase /

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

3
3ds, 2012-05-15
@3ds

I would advise you to look at the routing module of any framework, how they parse the request. For example SlimPHP, Zend Framework etc... PS Slim is small, I think it will do ;)

S
Sergey Tsepelev, 2012-05-15
@tsepelev

The easiest way to do this is:

<?php
//If is defined URL variable 'aboutme'
if(isset($_GET['aboutme'])){
// include page about me
include('include/in-aboutme.php');
//else if is defined URL variable 'interests'
}else if(isset($_GET['interests'])){
// include page interests
include('include/in-interest.php');
// in all other cases include the home page
} else {
include('include/in-home.php');
}
?>

Request pages like this - www.site.ru/?aboutme

G
Gregory, 2012-05-15
@difiso

It's called ClearUrl .
For apache, something like this (taken from somewhere from Google):

<Directory /var/www/example.com>
   RewriteEngine on
   RewriteBase /
   RewriteCond %{REQUEST_FILENAME} !-f
   RewriteCond %{REQUEST_FILENAME} !-d
   RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</Directory>

In the index.php file (you can also use blablabla.php , as in RewriteRule write) the GET parameter q will come (you can also page , according to taste and color, in general), which you will process.
That is, for this example, the following will be:
example.com/price will cause the server to call already example.com/index.php?q=price .
So example.com/price , example.com/?q=price and example.com/index.php?q=price are equivalent for the server, and I think you can guess what to serve to the user :)

D
d4rkr00t, 2012-05-15
@d4rkr00t

.htaccess to dig towards RewriteRule just haven't written them for a long time.

N
no1, 2012-05-15
@no1

server {
rewrite ^/page=(.*)$ /$1 last;
}

;)

V
Voenniy, 2012-05-15
@Voenniy

people can no longer live without frameworks for solving the simplest tasks :)
The simplest:
.htaccess index.php
RewriteEngine On
RewriteRule ^([^.]+)$ index.php


$args =  explode('/',trim($_SERVER['REQUEST_URI'], '/'))

accordingly, when requesting site.ru/price/catalog/123/foo/bar
in $args it will be
if($args[0] == 'price'){
    // делаем для цены. и тд и тп.
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question