2013-04-03 78 views
0

我創建的CMS使用一個名爲「filename」的變量,通過URL傳遞來生成頁面。用變量重寫URL(.htaccess)

我典型的URL看起來像這樣:

/index.php?filename=about.html 

我想修改我的URL看起來像這樣:

/about.html 

當然,我也希望我的網址時,第一次訪問該頁面看起來是這樣的:

/index.html 

(更換.php.html

我是新來的使用.htaccess文件,但真的想修改我的網址來看待這種方式,我希望這是可能的。多謝你們!

回答

1

試試這個:

Options +FollowSymLinks -MultiViews 

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f 
    RewriteRule ^([0-9a-zA-Z\-]+.html)$ index.php?filename=$1 [L,NC] 
</IfModule> 

例如,如果我運行:的var_dump($_GET);http://so.localhost/This-is-your-page.html結果是:

array (size=1) 
    'filename' => string 'This-is-your-page.html' (length=22) 

我希望我幫助。