.htaccess查询字符串到文件夹格式

时间:2011-09-24 01:03:23

标签: .htaccess query-string directory-structure

我有一个带查询字符串的查询网址,我想将其转换为文件夹结构化网址。

例如:

http://localhost/index.php?page=about-us
http://localhost/index.php?page=contact-us

我将如何将其转换为

http://localhost/index/page/about-us
http://localhost/page/about-us

我知道这可以用.htaccess完成。我只是不知道从哪里开始

1 个答案:

答案 0 :(得分:0)

你需要的东西......

Options +FollowSymLinks   
RewriteEngine On   

RewriteCond %{SCRIPT_FILENAME} !-d   
RewriteCond %{SCRIPT_FILENAME} !-f   

RewriteRule ^page/([-a-z-0-9]+)*/$ ./index.php?page=$1
RewriteRule ^index/page/([-a-z-0-9]+)*/$ ./index.php?page=$1