Вопрос

Okay, so I'm using the Zend 2 Framework and I followed the basic Zend MVC style. But lets say I want to add site.com/blog (and blog being a 3rd party application). So how do I got about adding this? How do I tell the framework to ignore /blog? Would this just be a .htaccess change? (I'm using Apache)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Thanks!

Это было полезно?

Решение 3

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_URI} !^blog.*$
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Другие советы

Try this:

<IfModule mod_rewrite.c>
 RewriteEngine On 
 RewriteBase /
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
</IfModule>

This will detect that /blog/ is a real directory and it will be accessed just fine. You can then have an htaccess file in the blog folder to do what ever rewrite you need there and that will override the base htaccess when accessing the blog directory

I think you've hit the nail on the head. ZF2 will only interpret its routes after the webserver does its magic - so it isn't really a factor (and shouldn't be!). For efficiency's sake, I would strongly recommend identifying the location of your blog as a separate location entity in your webserver config (so this never hits ZF2's shores). Nginx does this really gracefully, here's a sample config:

location ^~ /blog {
    root /var/www/example.com;
    index index.php index.html index.htm;
    try_files $uri $uri/ /blog/index.php;

    location ~ \.php {
        fastcgi_split_path_info ^(.*\.php)(.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_param PATH_INFO $fastcgi_path_info;
        fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
        fastcgi_pass 127.0.0.1:9000;
    }
}

All kinds of good things happen, you can keep your wordpress separate from your ZF2 (in every respect), and there's no performance impact. I haven't danced with Apache in awhile, but I'm certain there's an equivalent structure. Sides, go NGINX ;)

Good luck!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top