需要 htaccess 重写帮助

htaccess rewrite help needed

我正在尝试编写重写规则,但到目前为止无法实现我想要的。 我的站点在一个子目录中,htaccess 文件在该目录中。

我想要的是,如果我去 http://example.com/site/http://example.com/site/index.php 它应该重写为

http://example.com/site/index.php?key=2

key 的值不会改变。它是固定的。我希望它默认加载但隐藏在 url.

我试过的是,

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site/index.php?key=2& [L,QSA]
</IfModule>

它不起作用。 但是如果我去地址 http://example.com/site/anything 那么它就可以了。

你能帮我吗? 我不太懂htaccess。

提前致谢。

这样说:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/

RewriteRule ^(index\.php)?$ index.php?key=2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?key=2& [L,QSA]
</IfModule>