.htaccess - 主页 + 来自 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代码?
解决方案
你可以有这样的规则:
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]
推荐阅读
- javascript - 如何在 Svelte 中可靠地合并这两个数组中的对象并循环生成的数组?
- python - 如何有效地使用 numpy 掩码?
- python - 如何找到斐波那契数列中的第 n 个值?
- google-cloud-platform - 谷歌云运行构建权限被拒绝
- spring - Kafka Listener 在 spring 项目中启动失败
- dll - 在哪里插入链表,为什么?
- networking - 我可以通过便宜的路由器在计算机之间获得 3 GBit/s 吗?
- python-3.x - 如何在python中使用正则表达式获取值
- flutter - 如何在 Flutter App 中打开 PDF 文件并拥有可选视图?
- python - Discord.py bot 无法邀请用户加入公会