在不更改 URL 的情况下加载页面


loading a page without changing the url

我里面有太多RewriteRule .htaccess.

现在我喜欢删除这些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但使用原始路由的 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然后您可以签入索引.php文件并根据该$_GET['route']根据需要重新路由

如果

这是你要求的,我并不完全舒尔:

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

URI 类源

URI 类说明

使用给定的段,您现在可以在应用程序中执行操作,而无需将其硬编码到 .htaccess 中