-1

I'm making a project for some articles, I just heared about the .htaccess to make a clean url. so I have this example:

this articles should contain all articles

localhost/site-name/articles

and then, when someone click to see the full article, I want it to bacome like this:

localhost/site-name/articles/20/google-changes-its-logo

how to make this ?

1 Answers1

0

You can use rewrite module from apache see http://httpd.apache.org/docs/current/mod/mod_rewrite.html

Example:

RewriteEngine on

# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php
RewriteRule . index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]

What this will do is redirect everything to the index.php from there you can load the articles you want based on the url. Most frameworks already have a url routing feature.

Tim
  • 305
  • 2
  • 10
  • whish one is better ? – David Fernandez Mar 10 '16 at 10:44
  • What do you mean with "Which one". the example is just an option how you could tackle this problem. it strongly depends on what you would like to archive, like do you wan't to retrieve the data from a database and build the page from the data or do you wan't to retrieve a file in a directory? – Tim Mar 10 '16 at 10:53
  • I like to make a page for example `viewarticle` and display the full article in it but in url I want it like this: `localhost/site-name/articles/20/google-changes-its-logo` I want to remove the `viewarticle` from url – David Fernandez Mar 10 '16 at 11:04