#Need to write under liunx
rewriteengine on
rewriterule ([a-za-z]{1,})-([0-9]{1,}).html$ index.php?action=$1&id=$2
代码如下 |
复制代码 |
RewriteEngine on #开启重写
RewriteRule ^/$ index.php #表示用“/”就可以访问index.php
RewriteRule ^about_(d*)/$ about/about.php?id= #表示可以使用about_22/访问到about/about.php?id=22页面。注意$前面的“/”
RewriteRule ^about_(d*).html$ about/about.php?id= #表示可以使用about_22.html访问到about/about.php?id=22页面RewriteRule ^news_(d*)_(d*).html$ news/news.php?id=&page= #表示可以使用news_11_2.html访问到news/news.php?id=11&page=2页面。表示第一个参数,表示第二个参数
|
([a-za-z]{1,})-([0-9]{1,}).html$ is the rule, index.php?action=$1&id=$2 is the format to be replaced, $1 represents the A bracket matching value, $2 represents the second
Then restart apache
2. .htaccess Create a new file in the directory and name it .htaccess
, writing of .htaccess file
Create a file in the root directory of the website. The name is .htaccess and the writing method is:
The code is as follows
|
Copy code
代码如下 |
复制代码 |
< ?php
//利用server变量 取得PATH_INFO信息 该例中为 /1,100,8630.html 也就是执行脚本名后面的部分
if(@$path_info =$_SERVER["PATH_INFO"]){
//正则匹配一下参数
if(preg_match("//(d+),(d+),(d+).html/si",$path_info,$arr_path)){
$gid =intval($arr_path[1]); //取得值 1
$sid =intval($arr_path[2]); //取得值100
$softid =intval($arr_path[3]); //取得值8630
}else die("Path:Error!");
//相当于soft.php?gid=1&sid=100&softid=8630
}else die('Path:Nothing!');
//就是这么简单了。~)
?>
|
|
| RewriteEngine on #Turn on rewriting
RewriteRule ^/$ index.php #Indicates that you can access index.php with "/"
RewriteRule ^about_(d*)/$ about/about.php?id=$1 #Indicates that you can use about_22/ to access the about/about.php?id=22 page. Note the "/" in front of $
RewriteRule ^about_(d*).html$ about/about.php?id=$1 #Indicates that you can use about_22.html to access the about/about.php?id=22 page RewriteRule ^news_(d*)_(d*) .html$ news/news.php?id=$1&page=$2 #Indicates that you can use news_11_2.html to access the news/news.php?id=11&page=2 page. $1 represents the first parameter, $2 represents the second parameter
As can be seen from the above, if we have the following link
About us
Then the page we access is the same as the page accessed using the following
About us
2.php code
For example: http://www.xxxx.com/soft.php/1,100,8630.html
|