gpt4 book ai didi

.htaccess - 使用 .htaccess 从所有子目录中隐藏 index.php

转载 作者:行者123 更新时间:2023-12-01 13:36:02 24 4
gpt4 key购买 nike

所以我正在使用向我建议的文件结构构建一个电子商务网站,它看起来像这样:

http://www.sample.com/index.php
http://www.sample.com/department/index.php
http://www.sample.com/department/men/index.php

基本上我想去掉 url 中的所有 index.php 文件名,所以它看起来像这样:

http://www.sample.com
http://www.sample.com/department
http://www.sample.com/department/men

我通过在 .htaccess 中添加这段代码为我的主页实现了这一点:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]

但是,有什么方法可以通过编辑根 .htaccess 文件将此规则应用于我站点中的每个子目录?我猜这可以通过在每个目录的 .htaccess 文件中添加这条规则来完成,但我宁愿只有一个。

此外,这是否是构建网站的好方法?我不是特别喜欢它,因为有太多的 index.php 文件,但我不确定是否有更好的选择...

最佳答案

尝试将这些规则置于您在文档根目录中的 htaccess 文件中的规则:

RewriteRule ^index.php$ / [L,R=301]
RewriteRule ^(.+)/index.php$ /$1/ [L,R=301]

关于.htaccess - 使用 .htaccess 从所有子目录中隐藏 index.php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12055530/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com