【问题标题】:Setting redirect in .htaccess and keeping the paths在 .htaccess 中设置重定向并保留路径
【发布时间】:2017-10-28 09:37:09
【问题描述】:

我需要在 htaccess 中设置重定向。 我的 htaccess 在下面给出

RewriteEngine on
# If a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward it to index.php
RewriteRule . frontend/web/index.php

所以它将所有请求重定向到 frontend/web/index.php

但问题是假设以下请求来自 /site/about 目前使用上述规则 frontend/web/index.php 没有接收到路径参数。 IE。 /site/about 正在重定向到

我需要路径参数作为前端/web/index.php中的路径参数

.即。 /site/about 应该映射到 /frontend/web/index.php/site/about 路径部分也是动态的。即它可以是站点/服务之类的任何东西

如何在 htaccess 中执行该规则。我检查了其他一些解决方案,但其中大多数都说将路径参数映射到查询字符串,根据我的站点设置,我无法做到这一点。

【问题讨论】:

标签: php .htaccess cpanel


【解决方案1】:

您需要将原始路径附加到新路径:

RewriteRule (.*) frontend/web/index.php/$1

【讨论】:

    【解决方案2】:

    正如@Rickdenhaan 所说,您需要将请求路径附加到目标网址。您可以使用 %{REQUEST_URI} 变量或在重写目标末尾使用反向引用来附加它。

    将您的 RewriteRule 行更改为:

    RewriteRule . frontend/web/index.php%{REQUEST_URI} [L]
    

    【讨论】:

    • 请具体说明您遇到的问题。
    猜你喜欢
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-27
    • 1970-01-01
    • 2018-07-02
    • 2014-09-18
    • 1970-01-01
    相关资源
    最近更新 更多