2010-12-04 21 views

回答

3

假設你在Apache上運行,這個代碼在.htaccess工作對我來說:

RewriteEngine on 
RewriteRule ^([a-zA-Z0-9_-]+)/$ /index.php?parameter=$1 

根據您的網站結構可能需要的廣告,雖然一些規則。

0

如果您使用的是Apache,請使用mod重寫規則。這是製作虛擬目錄的更好和更安全的方式。

1

在您的Apache服務器上啓用mod_rewrite並使用.htaccess規則將請求重定向到控制器文件。

的.htaccess

# Enable rewrites 
RewriteEngine On 
# The following two lines skip over other HTML/PHP files or resources like CSS, Javascript and image files 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
# test.php is our controller file 
RewriteRule ^.*$ test.php [L] 

test.php的

$args = explode('/', $_SERVER['REDIRECT_URL']); // REDIRECT_URL is provided by Apache when a URL has been rewritten 
array_shift($args); 
$data = array(); 
for ($i = 0; $i < count($args); $i++) { 
    $k = $args[$i]; 
    $v = ++$i < count($args) ? $args[$i] : null; 
    $data[$k]= $v; 
} 
print_r($data); 

訪問URL http://localhost/abc/123/def/456會輸出如下:

Array 
(
    [abc] => 123 
    [def] => 456 
)