釋出:thatboy 來源:Net 【 大 中 小】 為大家介紹一個php url rewrite路徑重寫的例子,有需要的朋友,可以參考下。
本文原始連結: http://www.jbxue.com/article/7392.html
一、檔案 test.php
複制代碼 代碼示例: <?php
$id=$_GET["id"];
echo $id;
?>
首先 apache檔案裡
打開Apache配置檔案httpd.conf,找到如下:#LoadModule rewrite_module modules/mod_rewrite.so
開啟rewrite,去點前面"#"
二、重載Allowoverride
查找apache配置檔案找到如下:
複制代碼 代碼示例: <Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
将AllowOverride None 改為 AllowOverride All
在htaccess中暫時了解到三種url重定義
複制代碼 代碼示例: <IFMODULE mod_rewrite.c>
RewriteEngine On
#RewriteBase / (若檔案在根目錄下不必定義)
#RewriteRule ^t_(.*).html$ test.php?id=$1 [NC](打開test.php以t_id.html 比如 t_2.html 頁面輸出 id=2)
RewriteRule ^([0-9]+)$ test.php?id=$1 [NC](直接輸入id 比如 localhost/test/2 頁面輸出 id=2)
RewriteRule ^index.html$ index.php [NC](直接輸入index.html可打開index.php這個頁面)
</IFMODULE>
您可能感興趣的文章:
php 僞靜态(url重寫)的寫法