开发者

Gateway page system

开发者 https://www.devze.com 2022-12-29 07:00 出处:网络
I\'m trying to alter the way we currently provide a gateway page system within our CMS. What i mean by gateway page is mapping a non-existent URL to a page through a rewrite rule in the .htaccess, e.g

I'm trying to alter the way we currently provide a gateway page system within our CMS. What i mean by gateway page is mapping a non-existent URL to a page through a rewrite rule in the .htaccess, e.g.

RewriteRule ^foobar$ page.php?mode=bar&method=foo&id=1

This allows people to cre开发者_StackOverflowate short links to CMS pages for magazine adverts etc. The problem with this method is that it relies on access to the .htaccess. I would prefer a method that sits at code level but it occurs to me that - without a rewrite rule - a 404 error will be called. Is there any way to prevent this or work around this?


You can use a rewritemap within your htaccess. What this does is references an external file/script, passing it the incoming uri and getting back the rewritten uri.

In your .htaccess

RewriteMap shorts prg:/path/to/map.php

In your php file map.php

#!/path/to/php
$keyboard = fopen("php://stdin","r"); // get data from stdin
while (1) {
    $line = trim(fgets($keyboard));
    // fetch rewrite for line and echo out
}

The php file is passed the short url and returns - based on your logic - the full url

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号