Organize site by folders in directory

8

I'm venturing into my first website written in PHP and there's something bothering me, which is the way the site URL is, for example:

meusite.com/index.php?page=ucp&p=edit&id=58

The URL gets huge, I'd like to know the best way to organize the site by directory in folders, for example:

meusite.com/ucp/

Currently I only use an index calling the include function that leads to the folder where the pages are.

Thanks to anyone who can help.

    
asked by anonymous 23.05.2016 / 05:12

2 answers

2

I think I should have understood your question is very simple indeed.

If you just want to organize the URL and files in question, you can simply create a folder, for example, call ucp and index.php inside it and then access. meusite.com/ucp .

But if you just want to organize the URL and not mess with the rest, you might be using friendly URLs. What are friendly URLs? > Also has this tutorial, which teaches you how to create a friendly URL: Click here

If your problem is information on the page you want to have at all and why you're including the page through include , you can do just that. Create a file with the information you want to repeat and then add it to everyone you want.

    
28.05.2016 / 03:00
1

Hello, mate. In that case, it would appear that you use Friendly URLs with .htaccess, as mentioned in several of our companions' comments. In your case you should pass the parameters to the URL and so will open the file with the parameters accordingly. Here's an example:

RewriteEngine on
RewriteRule ^([a-zA-Z])/([a-zA-Z0-9_-]+)/([0-9])$ index.php?page=$1&p=$2&id=$3 [QSA]

In this case:

RewriteEngine on: A must for creating your friendly URLs. Put this above where you will specify your rules. RewriteRule: indicates the beginning of your rule. ^ ([a-zA-Z]) / ([a-zA-Z0-9 _-]) / ([0-9]) $ indicates with regular expressions the format of the URL that will fall into this In this case, the URL should start with a value of a up to uppercase or lowercase / a value up to uppercase or lowercase z or numbers, as well as "_" and "-" / numeric value . Finally, index.php? Page = $ 1 & p = $ 2 & id = $ 3 [QSA] indicates which URL it will access through this rule, specifying $ 1, $ 2 and $ 3 the regular expressions in their due parameters. [QSA] should appear at the end, to specify that your rule contains a query string ("Query String Append"), in this case, our parameters.

Using this rule I cited, link would be the same as accessing < em> link .

Important: Make sure apache mod rewrite is enabled.

    
13.07.2016 / 17:04