htaccess重定向<hostname> /?area = 0到<hostname> / </hostname> </hostname>

时间:2013-05-17 07:38:33

标签: apache .htaccess redirect rewrite

我只是想重定向/?area = 0链接到/ .. hostname可以是任何东西。我试过了:

redirectMatch 301 /?area=0 /index.php
RewriteRule ^/?area=0$ /index.php$1 [R=301,L]

还尝试了一些小变化,但没有重定向或导致内部服务器错误。只有当area为0且url不包含其他参数时,才必须进行重定向。

1 个答案:

答案 0 :(得分:1)

通过httpd.conf启用mod_rewrite和.htaccess,然后将此代码放在.htaccess目录下的DOCUMENT_ROOT中:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteCond %{QUERY_STRING} ^area=0(&|$) [NC]
RewriteRule ^$ /index.php? [L,R=302]

验证一切正常后,将R=302替换为R=301。在测试mod_rewrite规则时,请避免使用R=301(永久重定向)。

相关问题