【问题标题】:htaccess won't redirect to subfolder when given uri is just the host name当给定 uri 只是主机名时,htaccess 不会重定向到子文件夹
【发布时间】:2014-07-09 15:11:02
【问题描述】:

我正在使用 .htaccess 文件将所有请求重定向到位于子文件夹中的 index.php 文件。
文件夹和文件结构:

/var/www/html/.htaccess
/var/www/html/my-folder/index.php

主 html 文件夹中只有 .htaccess 文件和 my-folder 目录。

我的 .htaccess 文件内容是:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . /my-folder/index.php [L]

实际上所有请求都被重定向到正确的位置,即 my-folder 中的 index.php 文件。所有请求,但请求 url 只是主机名。例如:

www.my-host.com/path -> Redirects correctly
www.my-host.com/path/ -> Redirects correctly
www.my-host.com/path/another-path -> Redirects correctly
www.my-host.com/file.php -> Redirects correctly
www.my-host.com -> Won't redirect
www.my-host.com/ -> Won't redirect

我做错了什么?

【问题讨论】:

    标签: php .htaccess redirect


    【解决方案1】:

    您的模式中的 . 表示 URI 中必须包含某些内容,请尝试将其设为可选或改用 ^

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ /my-folder/index.php [L]
    

    【讨论】:

    • 我更改了我的 .htaccess,现在它看起来和你建议的完全一样,但仍然是同样的问题。
    猜你喜欢
    • 2018-01-12
    • 2012-06-24
    • 2015-11-19
    • 2014-04-03
    • 2017-01-05
    • 2013-01-20
    • 2014-06-01
    • 1970-01-01
    相关资源
    最近更新 更多