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

时间:2012-04-24 12:14:00

标签: php redirect seo

RewriteRule内的.htaccess太多了。

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

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

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

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

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

2 个答案:

答案 0 :(得分: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']重新路由{/ 1}

答案 1 :(得分:0)

如果这是你要求的话,我不完全是舒服的:

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

URI Class Source

URI Class Description

通过给定的细分,你现在可以在你的应用程序中做什么,而无需将其硬编码到.htaccess中

相关问题