1.創建.htaccess 文件
在網站文件夾根目錄,好比個人是test
2.在該文件中添加rewrite規則:
RewriteEngine on
RewriteRule ([a-zA-Z]{1,})-([0-9]{1,})\.html$ index.php?action=$1&id=$2
其中:rewriteengine爲重寫引擎開關on爲開啓off爲關閉
RewriteRule:RewriteRule是重寫規則,支持正則表達式
([a-zA-Z]{1,})-([0-9]{1,})\.html$是規則,index.php?action=$1&id=$2是要替換的格式,$1表明第一個括號匹配的值,$2表明第二個,如此類推!!
3.新建上述規則的對應php文件(index.php)
<?php
echo '你的Action是:' . $_GET['action'];
echo '<br/>';
echo '你的ID是:' . $_GET['id'];
?>
4.瀏覽器輸入localhost/test/view-12.html
可得以下結果: