当请求http://instagram.com/p/QeAuADr0yL被apache web服务器解析时,使用.htaccess文件中存储的代码,它知道第一个参数值为p,第二个参数值为hdashfdsahgofosa
您的请求可能被翻译为www.a.com/index.php?p1=a&p2=b
p1 和 p2 是变量,a 和 b 是它们的值
这些值可使用$_GET['a'] 和$_GET['b'] 方法获得;
我会给你一个完整的 htaccess 文件示例和规则:
RewriteRule ^([a-zA-Z-]+)/(product)-([0-9]+)$ index.php?action=$1&product=$3 [NC,L]
上面的代码在浏览器中看起来像www.a.com/aBcdE/product-1836455
它被翻译为:
$action = aBcde;
$product = 1836455;
第一个参数的值可以在 a-z 和/或 A-Z 之间
参数 2 的值介于 a-z A-Z 0-9 -
Options +SymLinksIfOwnerMatch
RewriteEngine on
RewriteRule ^([a-zA-Z-]+)/(producator)-([0-9]+)$ index.php?action=$1&producator=$3 [NC,L]
RewriteRule ^([a-zA-Z-]+)-([0-9]+)/(producator)-([0-9]+)$ index.php?action=$1&id=$2&producator=$4 [NC,L]
RewriteRule ^([a-zA-Z-]+)/(producatorx)-([0-9]+)$ index.php?action=$1&producatorx=$3 [NC,L]
RewriteRule ^([a-zA-Z-]+)-([0-9]+)/(producatorx)-([0-9]+)$ index.php?action=$1&id=$2&producatorx=$4 [NC,L]
RewriteRule ^([a-zA-Z-]+)$ index.php?action=$1 [NC,L]
RewriteRule ^([a-zA-Z-]+)-([0-9]+)$ index.php?action=$1&id=$2 [NC,L]
RewriteRule ^(tag)/([a-z0-9]+)$ index.php?action=tag&tag=$2 [NC,L]
RewriteRule ^([a-zA-Z-]+)-([0-9]+)/(update)-([a-z0-9]+)$ index.php?action=$1&id=$2&saction=update&code=$4 [NC,L]
RewriteRule ^([a-zA-Z-]+)-([0-9]+)/(delete)-([a-z0-9]+)$ index.php?action=$1&id=$2&saction=delete&code=$4 [NC,L]
RewriteRule ^([a-zA-Z-]+)-([0-9]+)/([a-zA-Z-]+)-([0-9]+)$ index.php?action=$1&id=$2&saction=$3&sid=$4 [NC,L]
RewriteRule ^(.*)-([0-9]+).html$ index.php?action=details&id=$2 [NC,L]