diff --git a/config/apache/standardebooks.org.conf b/config/apache/standardebooks.org.conf index 51413350..2273ce9c 100644 --- a/config/apache/standardebooks.org.conf +++ b/config/apache/standardebooks.org.conf @@ -81,6 +81,7 @@ Define domain standardebooks.org SetEnvIf Request_URI "\.epub3$" logdownload SetEnvIf Request_URI "\.azw3$" logdownload CustomLog /var/log/local/downloads.log "%h [%{%Y-%m-%d %H:%M:%S %Z}t] \"%r\" %>s %b" env=logdownload + DirectorySlash Off # Disable .htaccess files @@ -162,11 +163,28 @@ Define domain standardebooks.org RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.xml -f RewriteRule (.*) $1.xml [L] + # Remove trailing slashes + RewriteRule ^/(.+?)/$ /$1 [R=301,L] + + # Redirect index pages + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}/index.php -f + RewriteRule (.*) /$1/index.php + + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}/index.xml -f + RewriteRule (.*) /$1/index.xml + + # Remove newline characters inserted by accident in some email clients + RewriteRule ^(.*)\r\n[\ ]?(.*)$ $1$2 [R=301,N] + RewriteRule ^(.*)/r/n[\ ]?(.*)$ $1$2 [R=301,N] + RewriteRule ^(.*)/[rn]$ $1 [R=301,N] + # Favicon rewrites RewriteRule ^/(apple-touch|android-chrome|favicon|mstile|safari-pinned|browserconfig|manifest)([^/]+)$ /images/favicons/$1$2 [L] # Redirect tools - RewriteRule ^/tools/?$ https://github.com/standardebooks/tools [R=302,L] + RewriteRule ^/tools$ https://github.com/standardebooks/tools [R=302,L] # Redirect latest version of the manual RewriteRule ^/manual/latest(.*) /manual/index.php?url=$1 [L] @@ -188,25 +206,18 @@ Define domain standardebooks.org RewriteRule ^/ebooks/robert-louis-stevenson/treasure-island/milo-winter(.*?)$ /ebooks/robert-louis-stevenson/treasure-island$1 [R=301,L] RewriteRule ^/ebooks/edgar-rice-burroughs/a-princess-of-mars/frank-e-schoonover(.*?)$ /ebooks/edgar-rice-burroughs/a-princess-of-mars$1 [R=301,L] - # Remove newline characters inserted by accident in some email clients - RewriteRule ^(.*)\r\n[\ ]?(.*)$ $1$2 [R=301,N] - RewriteRule ^(.*)/r/n[\ ]?(.*)$ $1$2 [R=301,N] - RewriteRule ^(.*)/[rn]$ $1 [R=301,N] - # Redirect cover images with caching sha's to the root image # We do this because some sites like Google cache the cover image path, so changing it results in lots of 404s RewriteRule ^/images/covers/(.+?)\-[a-z0-9]{8}\-(cover|hero)(@2x)?\.jpg$ /images/covers/$1-$2$3.jpg - # Force a trailing slash on author directories - RewriteRule ^/(tags|collections|ebooks)/([^\./]+?)$ /$1/$2/ [R=301,L] - RewriteRule ^/ebooks/([^\./]+?)/$ /ebooks/author.php?url-path=$1 [QSA] - RewriteRule ^/tags/([^\./]+?)/$ /ebooks/index.php?tag=$1 [QSA] - RewriteRule ^/collections/([^\./]+?)/$ /ebooks/index.php?collection=$1 [QSA] + RewriteRule ^/ebooks/([^\./]+?)$ /ebooks/author.php?url-path=$1 [QSA] + RewriteRule ^/tags/([^\./]+?)$ /ebooks/index.php?tag=$1 [QSA] + RewriteRule ^/collections/([^\./]+?)$ /ebooks/index.php?collection=$1 [QSA] # Prevent this rule from firing if we're getting a distribution file RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/dist/.+$ RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/src/.+$ - RewriteRule ^/ebooks/([^\.]+?)/?$ /ebooks/ebook.php?url-path=$1 + RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1 diff --git a/config/apache/standardebooks.test.conf b/config/apache/standardebooks.test.conf index c7e44e2b..85c6185a 100644 --- a/config/apache/standardebooks.test.conf +++ b/config/apache/standardebooks.test.conf @@ -80,6 +80,7 @@ Define domain standardebooks.test SetEnvIf Request_URI "\.epub3$" logdownload SetEnvIf Request_URI "\.azw3$" logdownload CustomLog /var/log/local/downloads.log "%h [%{%Y-%m-%d %H:%M:%S %Z}t] \"%r\" %>s %b" env=logdownload + DirectorySlash Off # Disable .htaccess files @@ -161,11 +162,28 @@ Define domain standardebooks.test RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}.xml -f RewriteRule (.*) $1.xml [L] + # Remove trailing slashes + RewriteRule ^/(.+?)/$ /$1 [R=301,L] + + # Redirect index pages + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}/index.php -f + RewriteRule (.*) /$1/index.php + + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} -d + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME}/index.xml -f + RewriteRule (.*) /$1/index.xml + + # Remove newline characters inserted by accident in some email clients + RewriteRule ^(.*)\r\n[\ ]?(.*)$ $1$2 [R=301,N] + RewriteRule ^(.*)/r/n[\ ]?(.*)$ $1$2 [R=301,N] + RewriteRule ^(.*)/[rn]$ $1 [R=301,N] + # Favicon rewrites RewriteRule ^/(apple-touch|android-chrome|favicon|mstile|safari-pinned|browserconfig|manifest)([^/]+)$ /images/favicons/$1$2 [L] # Redirect tools - RewriteRule ^/tools/?$ https://github.com/standardebooks/tools [R=302,L] + RewriteRule ^/tools$ https://github.com/standardebooks/tools [R=302,L] # Redirect latest version of the manual RewriteRule ^/manual/latest(.*) /manual/index.php?url=$1 [L] @@ -182,27 +200,21 @@ Define domain standardebooks.test RewriteRule ^/ebooks/nikolai-gogol/short-fiction/claud-field_isabel-f-hapgood_vizetelly-and-company/(.+?)$ /ebooks/nikolai-gogol/short-fiction/claud-field_isabel-f-hapgood_vizetelly-and-company_george-tolstoy/$1 [R=301,L] RewriteRule ^/ebooks/h-g-wells/tales-of-space-and-time(.+)$ /ebooks/h-g-wells/short-fiction$1 [R=301,L] RewriteRule ^/ebooks/omar-khayyam/the-rubaiyat-of-omar-khayyam/edward-fitzgerald/edmund-dulac(.*?)$ /ebooks/omar-khayyam/the-rubaiyat-of-omar-khayyam/edward-fitzgerald$1 [R=301,L] + RewriteRule ^/ebooks/alfred-lord-tennyson/idylls-of-the-king/gustave-dore(.*?)$ /ebooks/alfred-lord-tennyson/idylls-of-the-king$1 [R=301,L] RewriteRule ^/ebooks/w-w-jacobs/the-lady-of-the-barge/maurice-greiffenhagen(.*?)$ /ebooks/w-w-jacobs/the-lady-of-the-barge$1 [R=301,L] RewriteRule ^/ebooks/robert-louis-stevenson/treasure-island/milo-winter(.*?)$ /ebooks/robert-louis-stevenson/treasure-island$1 [R=301,L] RewriteRule ^/ebooks/edgar-rice-burroughs/a-princess-of-mars/frank-e-schoonover(.*?)$ /ebooks/edgar-rice-burroughs/a-princess-of-mars$1 [R=301,L] - # Remove newline characters inserted by accident in some email clients - RewriteRule ^(.*)\r\n[\ ]?(.*)$ $1$2 [R=301,N] - RewriteRule ^(.*)/r/n[\ ]?(.*)$ $1$2 [R=301,N] - RewriteRule ^(.*)/[rn]$ $1 [R=301,N] - # Redirect cover images with caching sha's to the root image # We do this because some sites like Google cache the cover image path, so changing it results in lots of 404s RewriteRule ^/images/covers/(.+?)\-[a-z0-9]{8}\-(cover|hero)(@2x)?\.jpg$ /images/covers/$1-$2$3.jpg - # Force a trailing slash on author directories - RewriteRule ^/(tags|collections|ebooks)/([^\./]+?)$ /$1/$2/ [R=301,L] - RewriteRule ^/ebooks/([^\./]+?)/$ /ebooks/author.php?url-path=$1 [QSA] - RewriteRule ^/tags/([^\./]+?)/$ /ebooks/index.php?tag=$1 [QSA] - RewriteRule ^/collections/([^\./]+?)/$ /ebooks/index.php?collection=$1 [QSA] + RewriteRule ^/ebooks/([^\./]+?)$ /ebooks/author.php?url-path=$1 [QSA] + RewriteRule ^/tags/([^\./]+?)$ /ebooks/index.php?tag=$1 [QSA] + RewriteRule ^/collections/([^\./]+?)$ /ebooks/index.php?collection=$1 [QSA] # Prevent this rule from firing if we're getting a distribution file RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/dist/.+$ RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/src/.+$ - RewriteRule ^/ebooks/([^\.]+?)/?$ /ebooks/ebook.php?url-path=$1 + RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1 diff --git a/lib/Collection.php b/lib/Collection.php index fce46969..02cdc95e 100644 --- a/lib/Collection.php +++ b/lib/Collection.php @@ -5,6 +5,6 @@ class Collection{ public function __construct(string $name){ $this->Name = $name; - $this->Url = '/collections/' . strtolower(str_replace(' ', '-', Formatter::ToPlainText(Formatter::RemoveDiacritics($this->Name)))) . '/'; + $this->Url = '/collections/' . strtolower(str_replace(' ', '-', Formatter::ToPlainText(Formatter::RemoveDiacritics($this->Name)))); } } diff --git a/lib/Tag.php b/lib/Tag.php index da77e360..9e3fcbb6 100644 --- a/lib/Tag.php +++ b/lib/Tag.php @@ -5,6 +5,6 @@ class Tag{ public function __construct(string $name){ $this->Name = $name; - $this->Url = '/tags/' . strtolower(str_replace(' ', '-', Formatter::ToPlainText($this->Name))) . '/'; + $this->Url = '/tags/' . strtolower(str_replace(' ', '-', Formatter::ToPlainText($this->Name))); } } diff --git a/scripts/generate-opds.php b/scripts/generate-opds.php index b2e218ee..b35a13e1 100755 --- a/scripts/generate-opds.php +++ b/scripts/generate-opds.php @@ -11,7 +11,7 @@ print("\n"); /opds/all - + All Standard Ebooks Free and liberated ebooks, carefully produced for the true book lover. /images/logo.png diff --git a/templates/ContributeAlert.php b/templates/ContributeAlert.php index 13b0e37b..1e645bd9 100644 --- a/templates/ContributeAlert.php +++ b/templates/ContributeAlert.php @@ -1,5 +1,5 @@ diff --git a/templates/Footer.php b/templates/Footer.php index cd3f5c6a..33e39b0b 100644 --- a/templates/Footer.php +++ b/templates/Footer.php @@ -1,19 +1,19 @@