我在 .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/