假设我们有网址www.stackoverflow.com/hello/you/guys 如何将/(如果第二个和第三个斜杠)后的每个值作为变量? (比如:a =你好,b =你,c =伙计们)
f我只有一个/这个有效,但如果还有更多/:s我无法知道如何做 RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^/?([a-zA-ZåäöÅÄÖ0-9_-]+) /index.php?a=$1 [L]
答案 0 :(得分:2)
RewriteRule ^([^/]+)/?([^/]+)?/?([^/]+)?/?$ index.php?a=$1&b=$2&c=$3 [L,QSA]
但更好的方法是解析$ _SERVER ['REQUEST_URI']。
<强>更新强>
使用$ _SERVER ['REQUEST_URI']
htaccess的:
# Rewrite all URLs to index.php
RewriteRule .* /index.php [L]
的index.php:
$url = parse_url($_SERVER['REQUEST_URI']);
$params = explode('/', $url['path']);
var_dump($params);