-4

Does anyone know how I can change th architecture of my site url? I use Apache server and php 5.3 I have a site that outputs url as shown below

http://localhost/index.php?articleId=23

I want it to be outputting the url like

http://localhost/articles/hot-news-of-the-day

please give me a url to refer to for tutorials, pdf or even a sample code. U can also give me a sample code. Anything. Please!!!

Vyktor
  • 20,559
  • 6
  • 64
  • 96

5 Answers5

1

You want to look into URL Routing

A similar post is located here PHP Application URL Routing

Community
  • 1
  • 1
JConstantine
  • 3,980
  • 1
  • 33
  • 46
1

I think you are looking for mod_rewrite kind of stuff. Here's a link to a tutorial.

Eric
  • 217
  • 3
  • 4
  • 13
1

Look at apache mod_rewrite module:

Beginners guide to mod_rewrite

Apache rewriting guide

Waiting for Dev...
  • 12,629
  • 5
  • 47
  • 57
1

Within an .htaccess file in the root of your website folder you could use the following rules:

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^.+$ /index.php [L]

and use a routing script that will match your URL parameters to the corresponding functions. Easier yet, try using a framework that will do this for you, such as Codeigniter.

Roberto
  • 1,944
  • 1
  • 30
  • 42
1

Since you're using apache you'll need .htaccess file (or you could put it directly into configuration, it'll have better performance).

I recommend studying at least how AllowOverride works (if you want use .htaccess).

You will be using mod_rewrite, main and most important command is RewriteRule (though you may use we rewrite Conditions). You should also google for mod_rewrite tutorials, but basic example how your .htaccess file should look like is:

# Turn on rewirting
RewriteEngine On

# Not file, not directory
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d

# map /articles/* to index.php?article_title=*
RewriteRule ^/articles/(.+)$ /index.php?article_title=$1 [L]
Vyktor
  • 20,559
  • 6
  • 64
  • 96