简体   繁体   English

加载页面而不更改URL

[英]loading a page without changing the url

I have too many RewriteRule inside .htaccess . 我在.htaccess有太多RewriteRule

Now i like to remove those RewriteRule and use php to load or redirect my link. 现在,我想删除那些RewriteRule并使用php加载或重定向我的链接。

For that i use header but when i use it, my original urls in the browser are changing. 为此,我使用header但是当我使用header时,浏览器中的原始URL正在更改。

For example: My original link: http://test.com/something/someID , and when i use header, it change to : http://test.com/page.php?id= 例如:我的原始链接: http://test.com/something/someID : http://test.com/something/someID ,当我使用标题时,它更改为: http://test.com/page.php?id= : http://test.com/page.php?id= id http://test.com/page.php?id=

Bottom line i need something like vbseo (vbulletin) to management my link without using RewriteRule , but of course i have the below code inside .htaccess to redirect all my link to some specific page. 最重要的是,我需要使用vbseo(vbulletin)之类的东西来管理我的链接,而无需使用RewriteRule ,但是当然,我在.htaccess包含以下代码,将我的所有链接重定向到某个特定页面。

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

Just don't give any headers. 只是不要提供任何标题。 By default redirected links remain the same. 默认情况下,重定向的链接保持不变。 (even though the server redirects them, it's transprent to the client). (即使服务器将其重定向,也将透明地传递给客户端)。 So you need to pass it to index.php but with a GET value of the original route. 因此,您需要将其传递给index.php,但要使用原始路由的GET值。

So... 所以...

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]

So example.com/this/is/a/test would redirect to example.com/index.php?route=this/is/a/test which then you can check in your index.php file and reroute however you want based on that $_GET['route'] 因此example.com/this/is/a/test会重定向到example.com/index.php?route=this/is/a/test ,然后您可以签入index.php文件并根据需要重新路由$_GET['route']

Im not exactly shure if this is what you asked for: 我不是完全确定这是否是您要求的:

You could use a class like the Codeigniter URI class to get the single segments of your URI: 您可以使用诸如Codeigniter URI类之类的类来获取URI的单个段:

URI Class Source URI类来源

URI Class Description URI类说明

With the given segments you can now deside in your application what to do without hardcoding it into the .htaccess 有了给定的段,您现在可以在应用程序中放弃要做的事情而无需将其硬编码为.htaccess。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM