开发者

Please URL Rewrite in php

开发者 https://www.devze.com 2023-02-02 23:21 出处:网络
Pleas开发者_StackOverflow社区e how can I rewrite Could anybody please rewrite this url? http://localhost/display_news_cat.php?news_cat_id=14&p=2

Pleas开发者_StackOverflow社区e how can I rewrite

Could anybody please rewrite this url?

http://localhost/display_news_cat.php?news_cat_id=14&p=2

to

http://localhost/display_news_cat/14/2

Thank you


Create an .htaccess file in the site directory and add the following lines

RewriteEngine on
RewriteRule ^display_news_cat/([\d]+)/([\d]+)$ display_news_cat.php?news_cat=$1&p=$2


Afaik, this is normally accomplished with Apache .htaccess file rewrite rules. Is you case this would look something like:

RewriteEngine on
RewriteRule ^display_news_cat/([0-9]+)/([0-9]+)$ display_news_cat.php?news_cat_id=$1&p=$2

If this doesn't work, try checking your access logs to see what's happening.


there are different ways to archive this, and it takes only 1 minute to find this out yourself using google. you could:

  • use an .htacces file with rewrite-rules to let the apache do the rewriting
  • map everything on localhost/ to an index.php, read and parse the request-string "by hand" hand show the correct site


Also you can hold it in one script use GET to retrieve the values you wish and re-create the URL with that values. I don't know if it will help you.. Anyway a .httacess file will be much more useful for you.

0

精彩评论

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