How do I make a friendly url in PHP [duplicate]

3

I know you've asked before and you have several answers on the internet but none have solved my problem. I have a whole site in php, with several pages and would like to make url friendly to their variables. I wanted, for example, to let index.php be just / index and profile.php? Id = 2 turn profile / 2. Should I merge all the pages before making the URL friendly or can it do anyway?

Thanks in advance

    
asked by anonymous 09.02.2016 / 16:36

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"

You should change to

  

src="../ styles.css"

    
09.02.2016 / 16:48