开发者

Replace articles.php?id=123 with /articles/123-title-of-article

开发者 https://www.devze.com 2023-03-07 06:09 出处:网络
I am building a php+mysql site which will have numerous articles. I am pretty ok with html php jquery etc. I need to now what are the step开发者_运维百科s I need to take in order not have http://www.m

I am building a php+mysql site which will have numerous articles. I am pretty ok with html php jquery etc. I need to now what are the step开发者_运维百科s I need to take in order not have http://www.mysite.com/articles.php?id=123 but to have http://www.mysite.com/articles/123-title-of-article? Thanks


Well, you need, for instance, to store the token for each article (to optimize), like your example "123-title-of-article". Next step is to use .htaccess and mod_rewrite from Apache (if is your case).

If you will do it only on this articles "page folder" (articles/), I suggest to you make this folder valid and make the .htaccess inside that and redirect to articles.php?id={POST_ID_FOUND_BY_TOKEN}.

Take a look too on $_SERVER["REQUEST_*"] variables from PHP.

See: this page, on end of article have some examples.


The usual way to do this is by using mod_rewrite. You create a .htaccess file which, behind the scene, redirects the latter request to the former.

You can read about it here: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html


You'll need something called mod_rewrite, which is an apache module.

The configuration looks like this (stolen from a client's drupal install):

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteRule articles/(.*)$ articles.php?id=$1 [L,QSA]
</IfModule>

I haven't tested this, but it should work.

0

精彩评论

暂无评论...
验证码 换一张
取 消