Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

made domain optional

  • Loading branch information...
commit 5cd2701e9bd0b123a96c4e7ded2c9ea7ddba49d3 1 parent afd7594
Matt Curry authored
View
17 extras/nginx.conf
@@ -1,15 +1,14 @@
-# @TODO needs testing/confirming
location / {
- index index.php;
+ index index.php;
- # If the file exists as a static file serve it
+ # If the file exists as a static file serve it
# directly without running all
# the other rewite tests on it
- if (-f $request_filename) {
- break;
+ if (-f $request_filename) {
+ break;
}
- #HTML Cache
+ #HTML Cache
set $html_cache_file '';
set $html_cache_uri $request_uri;
#force trailing slash
@@ -20,15 +19,15 @@
set $html_cache_uri '';
}
if ($html_cache_uri ~ ^(.+)$) {
- set $html_cache_file /cache/$http_host/$1index.html;
+ set $html_cache_file /cache/$1index.html;
}
if (-f $document_root$html_cache_file) {
rewrite ^(.*)$ $html_cache_file break;
}
- #Default Handling
+ #Default Handling
if (!-f $request_filename) {
rewrite ^/(.+)$ /index.php?url=$1 last;
break;
}
- }
+ }
View
34 extras/nginx.host.conf
@@ -0,0 +1,34 @@
+# @TODO needs testing/confirming
+ location / {
+ index index.php;
+
+ # If the file exists as a static file serve it
+ # directly without running all
+ # the other rewite tests on it
+ if (-f $request_filename) {
+ break;
+ }
+
+ #HTML Cache
+ set $html_cache_file '';
+ set $html_cache_uri $request_uri;
+ #force trailing slash
+ if ($html_cache_uri ~* "^[\w\-\/]+[^\/?]$") {
+ set $html_cache_uri $html_cache_uri/;
+ }
+ if ($request_method = POST) {
+ set $html_cache_uri '';
+ }
+ if ($html_cache_uri ~ ^(.+)$) {
+ set $html_cache_file /cache/$http_host/$1index.html;
+ }
+ if (-f $document_root$html_cache_file) {
+ rewrite ^(.*)$ $html_cache_file break;
+ }
+
+ #Default Handling
+ if (!-f $request_filename) {
+ rewrite ^/(.+)$ /index.php?url=$1 last;
+ break;
+ }
+ }
View
9 extras/webroot.host.htaccess
@@ -0,0 +1,9 @@
+<IfModule mod_rewrite.c>
+ RewriteEngine On
+ RewriteCond %{REQUEST_METHOD} ^GET$
+ RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/$1/index.html -f
+ RewriteRule ^(.*)$ /cache/%{HTTP_HOST}/$1/index.html [L]
+ RewriteCond %{REQUEST_FILENAME} !-d
+ RewriteCond %{REQUEST_FILENAME} !-f
+ RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
+</IfModule>
View
6 extras/webroot.htaccess
@@ -1,9 +1,9 @@
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^GET$
- RewriteCond %{DOCUMENT_ROOT}/cache/%{HTTP_HOST}/$1/index.html -f
- RewriteRule ^(.*)$ /cache/%{HTTP_HOST}/$1/index.html [L]
+ RewriteCond %{DOCUMENT_ROOT}/cache/$1/index.html -f
+ RewriteRule ^(.*)$ /cache/$1/index.html [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
-</IfModule>
+</IfModule>
View
35 views/helpers/html_cache_base.php
@@ -20,8 +20,8 @@ class HtmlCacheBaseHelper extends Helper {
*/
public $options = array(
'test_mode' => false,
- 'www_root' => WWW_ROOT,
- 'host' => ''
+ 'host' => null,
+ 'domain' => false
);
/**
@@ -75,24 +75,27 @@ public function afterLayout() {
//handle 404s
if ($view->name == 'CakeError') {
- $this->path = $this->params['url']['url'];
+ $path = $this->params['url']['url'];
} else {
- $this->path = $this->here;
+ $path = $this->here;
}
- $this->path = implode(DS, array_filter(explode('/', $this->path)));
- if($this->path !== '') {
- $this->path = DS . ltrim($this->path, DS);
+ $path = implode(DS, array_filter(explode('/', $path)));
+ if($path !== '') {
+ $path = DS . ltrim($path, DS);
}
-
- $host = '';
- if (!empty($_SERVER['HTTP_HOST'])) {
- $host = $_SERVER['HTTP_HOST'] . '/';
- } elseif ($this->options['host']) {
- $host = $this->options['host'] . '/';
- }
- $this->path = $this->options['www_root'] . 'cache' . $host . $this->path . DS . 'index.html';
- $file = new File($this->path, true);
+
+ $host = '';
+ if($this->options['domain']) {
+ if (!empty($_SERVER['HTTP_HOST'])) {
+ $host = DS . $_SERVER['HTTP_HOST'];
+ } elseif ($this->options['host']) {
+ $host = DS . $this->options['host'];
+ }
+ }
+
+ $path = $this->options['www_root'] . 'cache' . $host . $path . DS . 'index.html';
+ $file = new File($path, true);
$file->write($view->output);
}

2 comments on commit 5cd2701

@mgcrea

issue on this commit
Notice (8): Undefined index: www_root [APP\plugins\html_cache\views\helpers\html_cache_base.php, line 97]

@mcurry
Owner

Thanks. Fixed now. Sorry it took so long.

Please sign in to comment.
Something went wrong with that request. Please try again.