php - 在不更改 url 的情况下加载页面

标签 php redirect seo

我在 .htaccess 中有太多的 RewriteRule

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

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

例如: 我的原始链接: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]

最佳答案

只是不要提供任何 header 。默认情况下,重定向链接保持不变。 (即使服务器重定向它们,它对客户端也是透明的)。因此,您需要将其传递给 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然后您可以 checkin 您的 index.php 文件并根据该 $_GET['route']

重新路由

关于php - 在不更改 url 的情况下加载页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10297596/

相关文章:

php - 让 PHPStan 理解 Laravel Eloquent Builder query()

php - fatal error : Call to a member function prepare() on null in on line 28

seo - 大型动态站点上的 XML 站点地图

seo - 从 Google 代码段中排除元素?

php,按引用或按值的变量

php - 如何制作 PHP 测试套件

php - PayPal Express Checkout 始终显示用户 "This transaction has expired."页面,但没有 API 错误

javascript - 使用 Jquery 重定向到哈希 url

Python HTTP HEAD - 正确处理重定向?

asp.net - 谷歌向网站链接添加奇怪的目录名称