Organize website by folders in directory

Asked

Viewed 635 times

8

I’m venturing into my first site written in PHP and there’s one thing that bothers me, which is the way the website URL looks, for example:

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

The URL gets huge, I would like to know what is the best way to organize the site by directory in folders, example:

meusite.com/ucp/

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

I thank anyone who can help.

  • 1

    Here’s how to use htacess: http://blog.thiagobelem.net/learning-urls-friends-withcomplex rules

  • 1

    I would recommend you to see some php framework to make your life easier. I would recommend Codeigniter. A hand on the wheel. However, as you said you are starting out, knowing how to program in pure language is important as well. htaccess is a solution to your problem.

  • Only by adding relevant information... for using . htacess, you need to have mod_rewrite enabled on your server.

  • The source code structure is sometimes the most convenient for organizing the URL. If you don’t need a framework, a library that does the URL routing can be useful. I recommend against using . htacess because it creates dependency on the HTTP server you are using, if you want to change pro Nginx then it will take work.

  • If it is what I am thinking it is quite simple. You just need to create a folder with the name you want and put the file index.php inside. If you are just organizing the URL, then you may be using friendly URL’s.

  • Did any of the answers help?

Show 1 more comment

2 answers

2

I believe I must have understood your question is very simple indeed.

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

But if what you want is just to organize the URL and not mess with the rest, you may be using friendly Urls. What are friendly Urls?
There’s also this tutorial, which teaches you how to create a user-friendly URL: Click here

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

  • then from what I understood on each page I put an index page together ?

1

Hello, mate. In this case, you would be using . htaccess Friendly URL, as mentioned in several comments from our teammates. In your case you should pass the parameters to the URL and thus open the file with the parameters accordingly. Here is an example:

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

In that case:

Rewriteengine on: Essential for creating your friendly URL’s. 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 in this rule, in which case the URL should start with some value from a to z upper or lower case / value from a to z upper or lower case or numbers, as well as "_" and "-" / numerical value. At the end, index.php? page=$1&p=$2&id=$3 [QSA] indicates which URL he will access through this rule, specifying with $1, $2 and $3 the regular expressions in their proper parameters. [QSA] should appear at the end, to specify that your rule contains a string for query ("Query String Append"), in this case, our parameters.

Using that rule I quoted, http://www.seusite.com/ucp/edit/58 would be the same thing to access http://www.seusite.com/index.php?page=ucp&p=edit&id=58.

Important: Be sure apache rewrite mod is enabled.

Browser other questions tagged

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