How do I make url friendly in PHP

Asked

Viewed 149 times

3

I know you’ve asked before and there are a lot of answers on the Internet but none of them have solved my problem. I have an entire site in php, with several pages and would like to make url friendly to their variables. For example, let index.php be just /index and profile.php? id=2 turn profile/2. Must join all pages before making the URL friendly or you can do so anyway?

Thanks in advance

  • 1

    Related: http://answall.com/questions/1326/como-posso-simplificar-os-urls-para-um-site

  • 1

    I was able to access the htacess and formulate the variables, but the images break, there is no stylesheet. I used the code: Rewriteengine On Rewritecond %{REQUEST_FILENAME} ! -f Rewritecond %{REQUEST_FILENAME} ! -d Rewriterule Fight/Battle/(.) Fight.php? Battle=$1 Rewriterule Citizen/profile/(.) profile.php? id=$1

  • 1

    read the related links and understand why css and js are not loading

1 answer

2


Well, create a. htaccess file and put the following:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteRule ^profile(|/)$ profile.php
RewriteRule ^profile/(.*)$ profile.php?id=$1

Not: you will need, on the "profile" page to change the files to css, image and etc if they are, for example, in the following format

src="/styles.css"

Should change to

src=".. /styles.css"

  • I did this, you mean change the stylesheet to . stylesheet in the header? And another, when I access a link from this page, it goes into /profile/5/index.php, for example

  • When you put the code in your htacces, it kind of "turns" the profile file into a folder. So, you should exit the folder with the links. So, before all links, you should put ".. /" (colon and slash). Example: if the link is at href="index" it should be at href=". /index"

  • So <? require_once('file.php'); ? > turns '.. /file.php' ?

  • Yes. Just like other links. But that’s only in the profile part

  • 2

    You’ve been very helpful, thank you. I use a general page for everything, to organize only the content in the profile, so I put a $directory variable with the website link (=http://meusite.com.br/) and used it instead of .. / Ta resolving. Thank you

  • Happy to have helped. Success with the site

  • Thank you very much, success life

Show 2 more comments

Browser other questions tagged

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