【问题标题】:remove everything from a url redirect to doc root从 url 重定向中删除所有内容到 doc root
【发布时间】:2019-04-11 15:09:14
【问题描述】:

我有一个网址说https://example.com/index.php/foo/bar

我希望 example.com 中的任何页面转到 https://example.com

我希望浏览器使用主页 url 进行更新。这是任何网址都可以访问该网站。这可能包括带有查询的网址,即https://example.com/?foo=bar。从字面上看,所有/任何页面都可以转到主页

我已经尝试了许多 RewriteRules 重定向,但没有一个做我想要的(最近的是加载 index.php,但 url 仍然是错误的)

我想使用 .htaccess 但如果在 .conf 文件中更容易,我会这样做

只是想我可以在 index.php 文件中执行此操作,方法是检查是否重新加载带有标题的页面是否有查询。会推荐这个吗?

我使用的是 ubuntu 16.04 apache 2.4,我有 php 7.1,所有模块都启用以处理重定向和重写(网站上有 wordpress,但现在包含即将推出的页面,没有其他内容)

htaccess 中当前但不工作的版本是

RewriteEngine On
RewriteBase /
# Make sure there is a query string
RewriteCond %{QUERY_STRING} .
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*  /? [R=301,L]

这将正确加载带有查询字符串 (https://example.com?foo=bar) 的 url,但如果我使用 https://example.com/index.php/foo/bar,浏览器不会更新重定向的 url/ index.php 中的脚本和图像未加载,并且与查询一样字符串的 url 在浏览器中保持不变。

【问题讨论】:

    标签: .htaccess


    【解决方案1】:

    将以下内容添加到我的 index.php 顶部解决了我的问题,而无需编辑 .conf 或 .htaccess 文件

    if ( $_SERVER['REQUEST_URI'] != '/index.php' ) {
        header("Location: /index.php");
        exit(0);
    }
    

    【讨论】:

      猜你喜欢
      • 2017-02-18
      • 1970-01-01
      • 2019-07-08
      • 2021-05-01
      • 2012-05-28
      • 2012-02-25
      • 1970-01-01
      • 2016-02-25
      • 1970-01-01
      相关资源
      最近更新 更多