【问题标题】:htaccess redirect from index page in subfolder to subfolderhtaccess 从子文件夹中的索引页面重定向到子文件夹
【发布时间】:2026-01-20 11:20:05
【问题描述】:

我的 webroot 中有一个名为 Country 的文件夹。我在这个子文件夹中有一个 index.html 页面。如果我输入 domain.com/country,我会得到 domain.com/app/webroot/country/。 如果我在国家后输入“/”,我会得到 domain.com/country/ 这就是我需要的。如何使用 htaccess 从 domain.com/country 重定向到 domain.com/country/

我希望该规则仅适用于国家文件夹。我有以下规则,但它适用于整个网站,我不想要。

    RewriteEngine on
# index.php to /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

我们将不胜感激。

【问题讨论】:

    标签: .htaccess url-rewriting


    【解决方案1】:

    尝试将以下内容添加到域根文件夹中的 .htaccess 文件中,优先于您拥有的任何其他规则

    RewriteEngine on
    RewriteBase /
    
    #if country does not have a trailing slash
    RewriteCond %{REQUEST_URI} ^/country$ [NC]
    #redirect to country with a trailing slash
    RewriteRule . /country/ [L,R=301]
    

    【讨论】: