How to access a page through dynamically friendly urls?

Asked

Viewed 58 times

0

Well, I must be wanting something very complicated for a beginner but come on ...

I’m starting a system where I need to create dynamic and friendly urls to register all the information regarding a page in the database and call this information when the page is accessed. The problem is I don’t know very well yet .htaccess. I ask for help!!!

htaccess

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule %{REQUEST_FILENAME} !-f
    RewriteRule %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?pagina=$1
</IfModule>

Question: How and what kind of relationship exists between the page and the content in the database so that when calling the url, the content comes. Something like, if it is /index.php? page=contact calls the content x <http://darte.axitech.com.br/index.php?pagina=contato>

With nay receive an error by typing <http://darte.axitech.com.br/contato> ... is that it is already actually redirecting, routing to /contact?

  • It all seems right, what’s the problem?

  • @bfavaretto what I ask is: how and what kind of relationship should I apply the page and the content in the database so that when calling the url, come the content. Something like, if it is /index.php? page=contact calls the content x ...

  • In index php you see what you have in $_GET['pagina']. It will be the name of the page. Based on this you pull up and display the appropriate content.

  • One way to do this in a more practical way would be to assign an ID to each page and then call the content by its ID?

  • Depends on what you want to do. /contato makes more sense than /72. In other cases, from collections with many items, it makes more sense to use the ID (sometimes followed by a Slug of the title).

  • I would recommend searching for php microframeworks, and using one that solves the routing for you.

  • But ... does this not influence SEO passing some parameter in the "friendly url"? Or is it not such a bad practice? Have another way to search the content without sending the file in the url?

  • You need to make it clear to PHP what content it has to deliver. And for SOE purposes you need to do this in the most elegant way possible. But what you go through depends on how your application/site is structured.

  • I don’t know if I understand your problem, but it seems to me that maybe you want pagina= be a php script, in case your index.php is calling by variable, but this is not required, it will depend on how to use the regex in case could do so RewriteRule "^(.*)(|/)$" "$1.php [QSA,L]" - QSA passes the GET parameters to a new page, if you access it like this: http://localhost/contato?foo=1 will point to something like /contato.php?foo=1, if you do so http://localhost/a/b/c/d?foo=1 will point to something like /a/b/c/d.php?foo=1

  • About the use of [L] i explained here http://answall.com/a/95399/3635

  • A doubt @Marcosvinicius that you are using with Codeigniter?

Show 6 more comments
No answers

Browser other questions tagged

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