Doubt about PHP or HTML Categories/Pages!

Asked

Viewed 35 times

0

Hello, I am creating a site and I am not using Wordpress because it is not a blog, and I would like a help, actually take a doubt, has how to make categories without being by folders? type you create a folder in www with name "videos" and put in it index.php these things, can you do this in PHP? without having to create a folder and show the videos there when you enter the category, I think my doubt is not comprehensive if someone does not understand I will reformulate.

  • 2

    I think what you want is URL rewriting. Search about this.

  • No Anderson, I would like to know how to make a category using PHP without using folders.

  • 1

    With the rewrite you can do this. You can create a file videos.php and make a URL localhost/videos run this file.

  • ha ok, I’ll see if I can find something related to that, thank you!

  • Thanks Anderson was that same, thanks man, can you reply to me mark as solved?

1 answer

0


Just detailing what was said by Anderson, Voce can use the URL rewriting.

--

The. htaccess (the file name is written this way, with a dot on the front) is a special file used by Apache (web server) that checks if there are any restrictions or special configuration for the accessed directory. It is with it that we will activate the URL rewriting and configure other necessary parameters.

Create the . htaccess file, insert the content below and save it in the root folder of your project (the same one where your index.php is located).

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

The first line enables rewriting.

The second and third lines tell Apache to ignore the rewrite if the address refers to a file ("f" of file) or folder ("d" of directory).

The fourth line tells Apache which rewrite rule will be applied. It basically captures everything that comes after index.php and returns as a parameter to the page. I won’t go too far in the details of this configuration, but in case you want to know more the answer, I recommend to see the documentation of Apache mod_rewrite.

There are some variations of this configuration, but this is the one I use.

OBS: Also remember to enable Apache mod_rewrite and restart it. If you don’t know how to do Google search according to your operating system.

--

Take a look at this blog: http://www.sergiotoledo.com.br/tutoriais/php/reescrita-de-url

Browser other questions tagged

You are not signed in. Login or sign up in order to post.