首页 > 解决方案 > 主页 + 来自 GET 参数的重定向值

问题描述

我需要file.php在我的网站上作为索引打开。在主页将打开file.php而不重定向到www.website.com/file.php

第二个重写规则重定向www.website.com/?id={id}www.website.com/{id}

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ file.php?id=$1
RewriteRule ^$ /file.php

RewriteCond %{QUERY_STRING} ^(.*&)?id=([^&]*)(&.*)?$
RewriteRule ^ %{REQUEST_URI}?%1%2%3

帮我提供htaccess代码?

标签: .htaccess

解决方案


你可以有这样的规则:

RewriteEngine On

RewriteCond %{THE_REQUEST} \s/+\?id=([^\s&]+)\s [NC]
RewriteRule ^ /%1? [R=301,L,NE]

RewriteRule ^$ /file.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ file.php?id=$1 [L,QSA]

推荐阅读