2013-04-03 75 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) 

我希望我帮助。