开发者

Alias Domain to Zend Directory

I have a ZF website at domainA.com and I'd like to alias domainB.com to something like: domainA.com/photos/album so that album would be the root开发者_Python百科 of domainB.

How might this be accomplished?


The first step here is to rewrite the URL to the correct route using mod_rewrite. Something like the following at the top of your exisitng .htaccess root should work:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{HTTP_HOST}    =domainB.com [NC]
RewriteCond %{REQUEST_URI} !^/photos/album
RewriteRule .* /photos/album/$0 [L]

This will redirect to /photos/album/ if no path is specified after domainB.com. If I remember correctly, Zend Framework isn't picky about whether your controllers/actions are terminated by a slash or not, so this should be fine. If it needs to be /photos/album for some reason, I have a solution for that as well, but it's overkill if it's not needed.

Later, your ruleset translates the URL to index.php, and Zend Framework does its routing. However, the default way Zend Framework does routing is to use REQUEST_URI, which happens to not be what we want in this case (It will be whatever was passed after domainB.com, instead of what we rewrote the request to). We actually need to use REDIRECT_URL, which is set by our new RewriteRule.

The controller request documentation describes this scenario (kind of), and explains that you can use Zend_Controller_Request_Apache404 as a drop-in request object to obtain the correct route information:

$request = new Zend_Controller_Request_Apache404();
$front->setRequest($request);

I'm fairly certain that you could also just get the current request object, and call

$request->setRequestUri($_SERVER['REDIRECT_URL']);

on it. Just condition this operation on the host, and hopefully it should all work out correctly.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜