使用 HTACCESS RewriteCondition,以便仅当输入 www.example.com 时才能访问 index.php

using HTACCESS RewriteCondition so that index.php can only be accessed ONLY when www.example.com is entered

提问人:Central Clinics Office Email 提问时间:10/28/2023 最后编辑:anubhavaCentral Clinics Office Email 更新时间:10/28/2023 访问量:23

问:

我一直在尝试找到一种方法,仅在没有扩展名的情况下输入网站时才将用户重定向到索引页面:

请看下面的例子:

当用户输入 localhost 时,我希望将它们重定向到 -> localhost/index.php

但。。。

当用户输入 localhost/index.php 时,我希望将它们重定向到 -> localhost/user.php?id=index.php

我在下面尝试了,但没有运气:

<IfModule mod_rewrite.c>
  RewriteCond %{HTTP_HOST} ^localhost
  RewriteRule (.*) /index.php [R=301,L]
</IfModule>

请让我知道我是否以正确的方式解决这个问题,或者我是否应该通过其他方法来解决这个问题。

Apache .ht访问

评论

0赞 anubhava 10/28/2023
当用户进入时会发生什么?localhost/style.css

答: 暂无答案