【问题标题】:redirect index to another page with address bar unchanged将索引重定向到地址栏不变的另一个页面
【发布时间】:2021-09-08 05:29:19
【问题描述】:

我在www.domain.com/subfolder/somepage.php 有一个页面,我需要www.domain.com 在不更改地址栏上显示的地址的情况下路由到它。

我试过Redirect /index.php /subfolder/somepage.php 但地址栏也会改变。

非常感谢!

【问题讨论】:

    标签: apache .htaccess redirect


    【解决方案1】:

    您可以使用 php 加载文件。

    <php 
    require_once '/subfolder/somepage.php';
    ?>
    

    或使用 htaccess 代理它

    RewriteCond %{REQUEST_URI} ^/index.php
    RewriteRule ^(.*)$ /subfolder/somepage.php [P] 
    

    【讨论】:

    • 谢谢!但是 [P] 对我不起作用,我不得不使用 [L]。请问有什么区别吗?
    • [L] 标志导致 mod_rewrite 停止处理规则集。在大多数情况下,这意味着如果规则匹配,则不会处理更多规则。 [P] 标志的使用导致请求由 mod_proxy 处理,并通过代理请求处理。来源:httpd.apache.org/docs/2.4/rewrite/flags.html
    • 感谢您的解释!
    猜你喜欢
    • 2018-04-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多