从URL中删除index.php?dir =?

时间:2012-02-10 21:58:37

标签: string .htaccess redirect

我有像

这样的链接结构
http://www.example.com/folder/index.php?dir=
http://www.example.com/folder/index.php?dir=first/
http://www.example.com/folder/index.php?dir=first/second/

依旧......

我想隐藏index.php?dir=,以便网址显示为人性化。

请帮我设置htaccess吗?

1 个答案:

答案 0 :(得分:1)

这是一个非常基本的设置.htaccess& mod_rewrite的:

RewriteEngine On

# Don't rewrite if the file or directory actually exists
# protects against a rewrite loop if index.php is hit
# and allows css, js, images not to be messed with
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Rewrite everything to the dir=parameter, appending any existing querystring with QSA
RewriteRule ^(.*)$ index.php?dir=$1 [L,QSA]

这应该启用像

这样的网址
  • http://example.com/first
  • http://example.com/first/second