需要htaccess重写帮助

时间:2015-03-09 21:15:23

标签: .htaccess url-rewriting

我试图写一个重写规则,但到目前为止还没有达到我想要的目的。 我的站点位于子目录中,htaccess文件位于该目录中。

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

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

key的价值不会发生变化。这是固定的。我希望它默认加载,但隐藏在网址中。

我尝试的是,

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

它不能正常工作。 但如果我去地址http://example.com/site/anything那就可以了。

你可以帮我吗? 我不太了解htaccess。

提前致谢。

1 个答案:

答案 0 :(得分:1)

这样做:

<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&$1 [L,QSA]
</IfModule>
相关问题