【问题标题】:RewriteBase not being applied未应用 RewriteBase
【发布时间】:2013-05-01 06:18:52
【问题描述】:

我似乎无法让我的 .htaccess 工作,我正在尝试将所有不是真实文件或文件夹的 url 重写到我的 index.php。我所在的目录是 /cms 重写似乎只在我使用这个 .htaccess 时才起作用

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /cms/index.php [L]
</IfModule>

当我尝试使用 RewriteBase /cms/ 并将最后一行更改为 . /index.php [L] 就像它的意思一样,重写不会重写为 localhost/cms/index.php 而是被重写为 localhost/index.php

【问题讨论】:

    标签: apache .htaccess wamp


    【解决方案1】:

    尝试使用这个版本:

    RewriteEngine On
    RewriteBase /cms/
    
    RewriteRule ^index\.php$ - [L]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . index.php [L]
    

    请注意,我使用 index.php 而不是 /index.php 和 RewriteBase 以确保加载相对 URI。

    【讨论】:

    • 完美运行,我很惊讶我没有意识到这一点。
    猜你喜欢
    • 2016-09-02
    • 1970-01-01
    • 2013-05-17
    • 2013-08-27
    • 2020-06-21
    • 1970-01-01
    • 1970-01-01
    • 2019-11-01
    • 2015-11-16
    相关资源
    最近更新 更多