【问题标题】:loading a page without changing the url在不更改 url 的情况下加载页面
【发布时间】:2012-04-24 12:14:00
【问题描述】:

.htaccess 里面的RewriteRule 太多了。

现在我想删除那些 RewriteRule 并使用 php 加载或重定向我的链接。

为此,我使用header,但是当我使用它时,我在浏览器中的原始网址正在改变。

例如: 我的原始链接:http://test.com/something/someID,当我使用标题时,它变为:http://test.com/page.php?id=

底线我需要像 vbseo (vbulletin) 这样的东西来管理我的链接而不使用 RewriteRule,但当然我在 .htaccess 中有以下代码将我的所有链接重定向到某个特定页面。

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php [L,QSA]

【问题讨论】:

    标签: php redirect seo


    【解决方案1】:

    只是不要提供任何标题。默认情况下,重定向链接保持不变。 (即使服务器重定向它们,它对客户端也是透明的)。因此,您需要将其传递给 index.php,但需要使用原始路由的 GET 值。

    所以...

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f    #If requested filename is not a file
    RewriteCond %{REQUEST_FILENAME} !-d    #If requested filename is not a directory
    RewriteRule ^(.+)$ index.php?route=$1 [L,QSA]
    

    所以example.com/this/is/a/test 将重定向到example.com/index.php?route=this/is/a/test,然后您可以检查您的index.php 文件并根据$_GET['route'] 重新路由您想要的路径

    【讨论】:

    • 我的问题是我没有t know have to display other page inside index without header`。
    【解决方案2】:

    如果这是您要求的,我不完全确定:

    您可以使用像 Codeigniter URI 类这样的类来获取 URI 的单个片段:

    URI Class Source

    URI Class Description

    有了给定的段,您现在可以在应用程序中决定要做什么,而无需将其硬编码到 .htaccess 中

    【讨论】:

    • CodeIgniter 也适用于 .htaccess。问题是你想用它做什么......
    猜你喜欢
    • 2016-10-28
    • 2020-10-04
    • 2013-07-07
    • 1970-01-01
    • 2020-04-20
    • 2012-06-02
    • 2013-06-21
    • 2020-12-29
    相关资源
    最近更新 更多