简体   繁体   中英

loading a page without changing the url

I have too many RewriteRule inside .htaccess .

Now i like to remove those RewriteRule and use php to load or redirect my link.

For that i use header but when i use it, my original urls in the browser are changing.

For example: My original link: http://test.com/something/someID , and when i use header, it change to : 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.

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.

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']

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:

URI Class Source

URI Class Description

With the given segments you can now deside in your application what to do without hardcoding it into the .htaccess

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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