From b340c55460a037b077564c361e1b64b9077a955b Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Mon, 11 Nov 2024 11:06:04 -0600 Subject: [PATCH] Move Apache rewrites into separate files --- config/apache/rewrites/artworks.conf | 9 ++ config/apache/rewrites/ebooks.conf | 45 ++++++++ config/apache/rewrites/feeds.conf | 10 ++ config/apache/rewrites/misc.conf | 21 ++++ config/apache/rewrites/newsletters.conf | 3 + config/apache/rewrites/polls.conf | 9 ++ config/apache/standardebooks.org.conf | 130 +++-------------------- config/apache/standardebooks.test.conf | 134 ++++-------------------- 8 files changed, 131 insertions(+), 230 deletions(-) create mode 100644 config/apache/rewrites/artworks.conf create mode 100644 config/apache/rewrites/ebooks.conf create mode 100644 config/apache/rewrites/feeds.conf create mode 100644 config/apache/rewrites/misc.conf create mode 100644 config/apache/rewrites/newsletters.conf create mode 100644 config/apache/rewrites/polls.conf diff --git a/config/apache/rewrites/artworks.conf b/config/apache/rewrites/artworks.conf new file mode 100644 index 00000000..a620df06 --- /dev/null +++ b/config/apache/rewrites/artworks.conf @@ -0,0 +1,9 @@ +RewriteRule ^/artworks/([^\./]+?)$ /artists/get.php?artist-url-name=$1 [L] + +RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" +RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L] + +RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" +RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/post.php?artist-url-name=$1&artwork-url-name=$2 [L] + +RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)/edit$ /artworks/edit.php?artist-url-name=$1&artwork-url-name=$2 [L] diff --git a/config/apache/rewrites/ebooks.conf b/config/apache/rewrites/ebooks.conf new file mode 100644 index 00000000..b365a992 --- /dev/null +++ b/config/apache/rewrites/ebooks.conf @@ -0,0 +1,45 @@ +# Rewrite ebook downloads +RewriteRule ^/ebooks/(.+?)/download$ /ebooks/download.php?url-path=$1 [QSA] + +# Misc ebook rewrites +RewriteRule ^/subjects/([^\./]+?)$ /ebooks/index.php?tags[]=$1 [QSA] +RewriteRule ^/ebooks/([^\./]+?)$ /ebooks/author.php?url-path=$1 [QSA] +RewriteRule ^/ebooks/([^\./]+?)/downloads$ /bulk-downloads/get.php?author=$1 [QSA] +RewriteRule ^/ebooks/([^\./]+?)/feeds$ /feeds/get.php?author=$1 [QSA] +RewriteRule ^/collections/([^\./]+?)$ /collections/get.php?collection=$1 [QSA] +RewriteRule ^/collections/([^/]+?)/downloads$ /bulk-downloads/get.php?collection=$1 +RewriteRule ^/collections/([^/]+?)/feeds$ /feeds/get.php?collection=$1 + +# List of specific URL rewrites +RewriteRule ^/contribute/accepted-ebooks/? /contribute/collections-policy [R=301,L] +RewriteRule ^/ebooks/aristotle/the-nicomachean-ethics(/?$|/.+?$) /ebooks/aristotle/nicomachean-ethics$1 [R=301,L] +RewriteRule ^/ebooks/sir-arthur-conan-doyle(/?$|/.+?$) /ebooks/arthur-conan-doyle$1 [R=301,L] +RewriteRule ^/ebooks/benjamin-disraeli/sibyl(/?$|/.+?$) /ebooks/benjamin-disraeli/sybil$1 [R=301,L] +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] +RewriteRule ^/ebooks/abraham-merritt/the-moon-pool(/?$|/.+?$) /ebooks/a-merritt/the-moon-pool$1 [R=301,L] +RewriteRule ^/ebooks/leo-tolstoy/a-confession/aylmer-maude_louise-maude(/?$|/.+?$) /ebooks/leo-tolstoy/a-confession/aylmer-maude$1 [R=301,L] +RewriteRule ^/ebooks/f-marion-crawford/khaled-a-tale-of-arabia(/?$|/.+?$) /ebooks/f-marion-crawford/khaled$1 [R=301,L] +RewriteRule ^/ebooks/h-rider-haggard/she/maurice-greiffenhagen_charles-h-m-kerr(/?$|/.+?$) /ebooks/h-rider-haggard/she$1 [R=301,L] +RewriteRule ^/ebooks/ivan-bunin/short-fiction/s-s-koteliansky_d-h-lawrence_leonard-woolf_bernard-guilbert-guerney_the-russian-review(/?$|/.+?$) /ebooks/ivan-bunin/short-fiction/s-s-koteliansky_d-h-lawrence_leonard-woolf_bernard-guilbert-guerney_the-russian-review_natalie-a-duddington$1 [R=301,L] +RewriteRule ^/ebooks/henry-david-thoreau/a-yankee-in-canada(/?$|/.+?$)$ /ebooks/henry-david-thoreau/essays$1 [R=301,L] +RewriteRule ^/ebooks/mark-twain/the-autobiography(/?$|/.+?$)$ /ebooks/mark-twain/the-autobiography-of-mark-twain$1 [R=301,L] +RewriteRule ^/ebooks/e-nesbit/the-enchanted-castle/h-r-millar(/?$|/.+?$) /ebooks/e-nesbit/the-enchanted-castle$1 [R=301,L] +RewriteRule ^/ebooks/epictetus/the-enchiridion/elizabeth-carter(/?$|/.+?$) /ebooks/epictetus/short-works/george-long$1 [R=301,L] +RewriteRule ^/ebooks/taras-shevchenko/poetry/alexander-jardine-hunter_ethel-lilian-voynich_paul-selver_florence-randal-livesay(/?$|/.+?$) /ebooks/taras-shevchenko/poetry/alexander-jardine-hunter_ethel-voynich_paul-selver_florence-randal-livesay$1 [R=301,L] +RewriteRule ^/ebooks/nikolai-gogol/dead-souls/d-j-hogarth(/?$|/.+?$) /ebooks/nikolai-gogol/dead-souls/c-j-hogarth$1 [R=301,L] +RewriteRule ^/ebooks/sigfrid-siwertz/downstream/macmillan-of-canada(/?$|/.+?$) /ebooks/sigfrid-siwertz/downstream/e-classen$1 [R=301,L] +RewriteRule ^/ebooks/samuel-richardson/clarissa-harlowe(/?$|/.+?$) /ebooks/samuel-richardson/clarissa$1 [R=301,L] + +# Rewrite ebooks taken down due to copyright clarifications +RewriteRule ^/ebooks/jules-verne/twenty-thousand-leagues-under-the-seas/f-p-walter.* - [R=451,L] + +# Prevent this rule from firing if we're getting a distribution file +RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/downloads/.+$ +RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/text.*$ +RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1 diff --git a/config/apache/rewrites/feeds.conf b/config/apache/rewrites/feeds.conf new file mode 100644 index 00000000..565b58ad --- /dev/null +++ b/config/apache/rewrites/feeds.conf @@ -0,0 +1,10 @@ +# Redirect old feed URLs +RewriteRule ^/(opds|rss|atom)(.*)$ /feeds/$1$2 [R=301,L] + +# If we ask for /opds/all?query=xyz, rewrite that to the search page. +RewriteCond %{QUERY_STRING} \bquery= +RewriteRule ^/feeds/(opds|atom|rss)/all.xml$ /feeds/$1/search.php [QSA] + +RewriteRule ^/feeds/(atom|rss)/([^/\.]+)$ /feeds/collection.php?type=$1&class=$2 + +RewriteRule ^/feeds/(.+\.xml)$ /feeds/download.php?path=$1 diff --git a/config/apache/rewrites/misc.conf b/config/apache/rewrites/misc.conf new file mode 100644 index 00000000..3e323c54 --- /dev/null +++ b/config/apache/rewrites/misc.conf @@ -0,0 +1,21 @@ +# 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] + +# Redirect latest version of the manual +RewriteRule ^/manual/latest(.*) /manual/index.php?url=$1 [L] + +# Work around some naughty hotlinkers +RewriteCond %{HTTP_REFERER} !^$ +RewriteCond %{HTTP_REFERER} ^https?://.*medialibrary.it [NC] +RewriteRule ^(/ebooks/.+/downloads/|/images/covers/) /images/do-not-hotlink.jpg [R=301,L,NC] + +# 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|avif)$ /images/covers/$1-$2$3.$4 + +# Rewrite rules for bulk downloads +RewriteRule ^/bulk-downloads/(.+\.zip)$ /bulk-downloads/download.php?path=$1 +RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?class=$1 diff --git a/config/apache/rewrites/newsletters.conf b/config/apache/rewrites/newsletters.conf new file mode 100644 index 00000000..ca64c1cc --- /dev/null +++ b/config/apache/rewrites/newsletters.conf @@ -0,0 +1,3 @@ +RewriteRule ^/newsletter$ /newsletter/subscriptions/new.php [L] +RewriteRule ^/newsletter/subscriptions/([^/\.]+?)$ /newsletter/subscriptions/get.php?uuid=$1 [L] +RewriteRule ^/newsletter/subscriptions/([^/\.]+?)/(confirm|delete)$ /newsletter/subscriptions/$2.php?uuid=$1 [L] diff --git a/config/apache/rewrites/polls.conf b/config/apache/rewrites/polls.conf new file mode 100644 index 00000000..33a765d1 --- /dev/null +++ b/config/apache/rewrites/polls.conf @@ -0,0 +1,9 @@ +RewriteRule ^/polls/([^/\.]+)$ /polls/get.php?pollurlname=$1 [L] +RewriteRule ^/polls/([^/\.]+)/votes/new$ /polls/votes/new.php?pollurlname=$1 [L] +RewriteRule ^/polls/([^/\.]+)/votes/([0-9]+)$ /polls/votes/get.php?pollurlname=$1&userid=$2 [L] + +RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" +RewriteRule ^/polls/([^/\.]+)/votes$ /polls/votes/index.php?pollurlname=$1 [L] + +RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" +RewriteRule ^/polls/([^/\.]+)/votes$ /polls/votes/post.php?pollurlname=$1 [L] diff --git a/config/apache/standardebooks.org.conf b/config/apache/standardebooks.org.conf index aff25da1..43372448 100644 --- a/config/apache/standardebooks.org.conf +++ b/config/apache/standardebooks.org.conf @@ -50,7 +50,8 @@ SSLStaplingResponderTimeout 5 SSLStaplingReturnResponderErrors off Define domain standardebooks.org -Define webroot /standardebooks.org/web +Define web_root /standardebooks.org/web +Define conf_rewrite_root ${web_root}/config/apache/rewrites ServerName standardebooks.com @@ -78,7 +79,7 @@ Define webroot /standardebooks.org/web ServerName ${domain} ServerAlias www.${domain} - DocumentRoot ${webroot}/www + DocumentRoot ${web_root}/www ErrorDocument 404 /404 ErrorDocument 451 /451 ErrorLog /var/log/local/www-error.log @@ -92,7 +93,7 @@ Define webroot /standardebooks.org/web Header always set Strict-Transport-Security "max-age=15768000" Header set Content-Security-Policy "default-src 'self';" - + # Disable .htaccess files AllowOverride none @@ -209,131 +210,32 @@ Define webroot /standardebooks.org/web 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] - - # Redirect latest version of the manual - RewriteRule ^/manual/latest(.*) /manual/index.php?url=$1 [L] - - # Rewrite ebook downloads - RewriteRule ^/ebooks/(.+?)/download$ /ebooks/download.php?url-path=$1 [QSA] - - # Work around some naughty hotlinkers - RewriteCond %{HTTP_REFERER} !^$ - RewriteCond %{HTTP_REFERER} ^https?://.*medialibrary.it [NC] - RewriteRule ^(/ebooks/.+/downloads/|/images/covers/) /images/do-not-hotlink.jpg [R=301,L,NC] - - # List of specific URL rewrites - RewriteRule ^/contribute/accepted-ebooks/? /contribute/collections-policy [R=301,L] - RewriteRule ^/ebooks/aristotle/the-nicomachean-ethics(/?$|/.+?$) /ebooks/aristotle/nicomachean-ethics$1 [R=301,L] - RewriteRule ^/ebooks/sir-arthur-conan-doyle(/?$|/.+?$) /ebooks/arthur-conan-doyle$1 [R=301,L] - RewriteRule ^/ebooks/benjamin-disraeli/sibyl(/?$|/.+?$) /ebooks/benjamin-disraeli/sybil$1 [R=301,L] - 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] - RewriteRule ^/ebooks/abraham-merritt/the-moon-pool(/?$|/.+?$) /ebooks/a-merritt/the-moon-pool$1 [R=301,L] - RewriteRule ^/ebooks/leo-tolstoy/a-confession/aylmer-maude_louise-maude(/?$|/.+?$) /ebooks/leo-tolstoy/a-confession/aylmer-maude$1 [R=301,L] - RewriteRule ^/ebooks/f-marion-crawford/khaled-a-tale-of-arabia(/?$|/.+?$) /ebooks/f-marion-crawford/khaled$1 [R=301,L] - RewriteRule ^/ebooks/h-rider-haggard/she/maurice-greiffenhagen_charles-h-m-kerr(/?$|/.+?$) /ebooks/h-rider-haggard/she$1 [R=301,L] - RewriteRule ^/ebooks/ivan-bunin/short-fiction/s-s-koteliansky_d-h-lawrence_leonard-woolf_bernard-guilbert-guerney_the-russian-review(/?$|/.+?$) /ebooks/ivan-bunin/short-fiction/s-s-koteliansky_d-h-lawrence_leonard-woolf_bernard-guilbert-guerney_the-russian-review_natalie-a-duddington$1 [R=301,L] - RewriteRule ^/ebooks/henry-david-thoreau/a-yankee-in-canada(/?$|/.+?$)$ /ebooks/henry-david-thoreau/essays$1 [R=301,L] - RewriteRule ^/ebooks/mark-twain/the-autobiography(/?$|/.+?$)$ /ebooks/mark-twain/the-autobiography-of-mark-twain$1 [R=301,L] - RewriteRule ^/ebooks/e-nesbit/the-enchanted-castle/h-r-millar(/?$|/.+?$) /ebooks/e-nesbit/the-enchanted-castle$1 [R=301,L] - RewriteRule ^/ebooks/epictetus/the-enchiridion/elizabeth-carter(/?$|/.+?$) /ebooks/epictetus/short-works/george-long$1 [R=301,L] - RewriteRule ^/ebooks/taras-shevchenko/poetry/alexander-jardine-hunter_ethel-lilian-voynich_paul-selver_florence-randal-livesay(/?$|/.+?$) /ebooks/taras-shevchenko/poetry/alexander-jardine-hunter_ethel-voynich_paul-selver_florence-randal-livesay$1 [R=301,L] - RewriteRule ^/ebooks/nikolai-gogol/dead-souls/d-j-hogarth(/?$|/.+?$) /ebooks/nikolai-gogol/dead-souls/c-j-hogarth$1 [R=301,L] - RewriteRule ^/ebooks/sigfrid-siwertz/downstream/macmillan-of-canada(/?$|/.+?$) /ebooks/sigfrid-siwertz/downstream/e-classen$1 [R=301,L] - RewriteRule ^/ebooks/samuel-richardson/clarissa-harlowe(/?$|/.+?$) /ebooks/samuel-richardson/clarissa$1 [R=301,L] - - # Rewrite ebooks taken down due to copyright clarifications - RewriteRule ^/ebooks/jules-verne/twenty-thousand-leagues-under-the-seas/f-p-walter.* - [R=451,L] - - # 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|avif)$ /images/covers/$1-$2$3.$4 - - RewriteRule ^/ebooks/([^\./]+?)$ /ebooks/author.php?url-path=$1 [QSA] - RewriteRule ^/ebooks/([^\./]+?)/downloads$ /bulk-downloads/get.php?author=$1 [QSA] - RewriteRule ^/ebooks/([^\./]+?)/feeds$ /feeds/get.php?author=$1 [QSA] - RewriteRule ^/subjects/([^\./]+?)$ /ebooks/index.php?tags[]=$1 [QSA] - RewriteRule ^/collections/([^\./]+?)$ /collections/get.php?collection=$1 [QSA] - RewriteRule ^/collections/([^/]+?)/downloads$ /bulk-downloads/get.php?collection=$1 - RewriteRule ^/collections/([^/]+?)/feeds$ /feeds/get.php?collection=$1 - - # Prevent this rule from firing if we're getting a distribution file - RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/downloads/.+$ - RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/text.*$ - RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1 - - # Newsletter - RewriteRule ^/newsletter$ /newsletter/subscriptions/new.php [L] - RewriteRule ^/newsletter/subscriptions/([^/\.]+?)$ /newsletter/subscriptions/get.php?uuid=$1 [L] - RewriteRule ^/newsletter/subscriptions/([^/\.]+?)/(confirm|delete)$ /newsletter/subscriptions/$2.php?uuid=$1 [L] - - # Polls - RewriteRule ^/polls/([^/\.]+)$ /polls/get.php?pollurlname=$1 [L] - RewriteRule ^/polls/([^/\.]+)/votes/new$ /polls/votes/new.php?pollurlname=$1 [L] - RewriteRule ^/polls/([^/\.]+)/votes/([0-9]+)$ /polls/votes/get.php?pollurlname=$1&userid=$2 [L] - - RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" - RewriteRule ^/polls/([^/\.]+)/votes$ /polls/votes/index.php?pollurlname=$1 [L] - - RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" - RewriteRule ^/polls/([^/\.]+)/votes$ /polls/votes/post.php?pollurlname=$1 [L] - - # Rewrite rules for feeds eeds - # Redirect old feed URLs - RewriteRule ^/(opds|rss|atom)(.*)$ /feeds/$1$2 [R=301,L] - - # If we ask for /opds/all?query=xyz, rewrite that to the search page. - RewriteCond %{QUERY_STRING} \bquery= - RewriteRule ^/feeds/(opds|atom|rss)/all.xml$ /feeds/$1/search.php [QSA] - - RewriteRule ^/feeds/(atom|rss)/([^/\.]+)$ /feeds/collection.php?type=$1&class=$2 - - RewriteRule ^/feeds/(.+\.xml)$ /feeds/download.php?path=$1 - - # Rewrite rules for bulk downloads - RewriteRule ^/bulk-downloads/(.+\.zip)$ /bulk-downloads/download.php?path=$1 - RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?class=$1 - - # Rewrite rules for cover art - RewriteRule ^/artworks/([^\./]+?)$ /artists/get.php?artist-url-name=$1 [L] - - RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" - RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L] - - RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" - RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/post.php?artist-url-name=$1&artwork-url-name=$2 [L] - - RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)/edit$ /artworks/edit.php?artist-url-name=$1&artwork-url-name=$2 [L] + Include ${conf_rewrite_root}/misc.conf + Include ${conf_rewrite_root}/feeds.conf + Include ${conf_rewrite_root}/ebooks.conf + Include ${conf_rewrite_root}/newsletters.conf + Include ${conf_rewrite_root}/artworks.conf + Include ${conf_rewrite_root}/polls.conf # Specific config for /ebooks///downloads - + # Both directives are required XSendFile on - XSendFilePath ${webroot}/www/ebooks + XSendFilePath ${web_root}/www/ebooks # Specific config for /bulk-downloads - + # Both directives are required XSendFile on - XSendFilePath ${webroot}/www/bulk-downloads + XSendFilePath ${web_root}/www/bulk-downloads # Specific config for /feeds - + # This must be defined at the top level /feeds/ directory # Both directives are required XSendFile on - XSendFilePath ${webroot}/www/feeds + XSendFilePath ${web_root}/www/feeds diff --git a/config/apache/standardebooks.test.conf b/config/apache/standardebooks.test.conf index 5c71624b..2615473c 100644 --- a/config/apache/standardebooks.test.conf +++ b/config/apache/standardebooks.test.conf @@ -50,7 +50,8 @@ SSLStaplingResponderTimeout 5 SSLStaplingReturnResponderErrors off Define domain standardebooks.test -Define webroot /standardebooks.org/web +Define web_root /standardebooks.org/web +Define conf_rewrite_root ${web_root}/config/apache/rewrites ServerName ${domain} @@ -61,7 +62,7 @@ Define webroot /standardebooks.org/web ServerName ${domain} ServerAlias www.${domain} - DocumentRoot ${webroot}/www + DocumentRoot ${web_root}/www ErrorDocument 404 /404 ErrorDocument 451 /451 ErrorLog /var/log/local/www-error.log @@ -69,12 +70,12 @@ Define webroot /standardebooks.org/web RewriteEngine on SSLEngine on - SSLCertificateFile ${webroot}/config/ssl/${domain}.crt - SSLCertificateKeyFile ${webroot}/config/ssl/${domain}.key + SSLCertificateFile ${web_root}/config/ssl/${domain}.crt + SSLCertificateKeyFile ${web_root}/config/ssl/${domain}.key Header always set Strict-Transport-Security "max-age=15768000" Header set Content-Security-Policy "default-src 'self';" - + # Disable .htaccess files AllowOverride none @@ -191,131 +192,32 @@ Define webroot /standardebooks.org/web 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] - - # Redirect latest version of the manual - RewriteRule ^/manual/latest(.*) /manual/index.php?url=$1 [L] - - # Rewrite ebook downloads - RewriteRule ^/ebooks/(.+?)/download$ /ebooks/download.php?url-path=$1 [QSA] - - # Work around some naughty hotlinkers - RewriteCond %{HTTP_REFERER} !^$ - RewriteCond %{HTTP_REFERER} ^https?://.*medialibrary.it [NC] - RewriteRule ^(/ebooks/.+/downloads/|/images/covers/) /images/do-not-hotlink.jpg [R=301,L,NC] - - # List of specific URL rewrites - RewriteRule ^/contribute/accepted-ebooks/? /contribute/collections-policy [R=301,L] - RewriteRule ^/ebooks/aristotle/the-nicomachean-ethics(/?$|/.+?$) /ebooks/aristotle/nicomachean-ethics$1 [R=301,L] - RewriteRule ^/ebooks/sir-arthur-conan-doyle(/?$|/.+?$) /ebooks/arthur-conan-doyle$1 [R=301,L] - RewriteRule ^/ebooks/benjamin-disraeli/sibyl(/?$|/.+?$) /ebooks/benjamin-disraeli/sybil$1 [R=301,L] - 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] - RewriteRule ^/ebooks/abraham-merritt/the-moon-pool(/?$|/.+?$) /ebooks/a-merritt/the-moon-pool$1 [R=301,L] - RewriteRule ^/ebooks/leo-tolstoy/a-confession/aylmer-maude_louise-maude(/?$|/.+?$) /ebooks/leo-tolstoy/a-confession/aylmer-maude$1 [R=301,L] - RewriteRule ^/ebooks/f-marion-crawford/khaled-a-tale-of-arabia(/?$|/.+?$) /ebooks/f-marion-crawford/khaled$1 [R=301,L] - RewriteRule ^/ebooks/h-rider-haggard/she/maurice-greiffenhagen_charles-h-m-kerr(/?$|/.+?$) /ebooks/h-rider-haggard/she$1 [R=301,L] - RewriteRule ^/ebooks/ivan-bunin/short-fiction/s-s-koteliansky_d-h-lawrence_leonard-woolf_bernard-guilbert-guerney_the-russian-review(/?$|/.+?$) /ebooks/ivan-bunin/short-fiction/s-s-koteliansky_d-h-lawrence_leonard-woolf_bernard-guilbert-guerney_the-russian-review_natalie-a-duddington$1 [R=301,L] - RewriteRule ^/ebooks/henry-david-thoreau/a-yankee-in-canada(/?$|/.+?$)$ /ebooks/henry-david-thoreau/essays$1 [R=301,L] - RewriteRule ^/ebooks/mark-twain/the-autobiography(/?$|/.+?$)$ /ebooks/mark-twain/the-autobiography-of-mark-twain$1 [R=301,L] - RewriteRule ^/ebooks/e-nesbit/the-enchanted-castle/h-r-millar(/?$|/.+?$) /ebooks/e-nesbit/the-enchanted-castle$1 [R=301,L] - RewriteRule ^/ebooks/epictetus/the-enchiridion/elizabeth-carter(/?$|/.+?$) /ebooks/epictetus/short-works/george-long$1 [R=301,L] - RewriteRule ^/ebooks/taras-shevchenko/poetry/alexander-jardine-hunter_ethel-lilian-voynich_paul-selver_florence-randal-livesay(/?$|/.+?$) /ebooks/taras-shevchenko/poetry/alexander-jardine-hunter_ethel-voynich_paul-selver_florence-randal-livesay$1 [R=301,L] - RewriteRule ^/ebooks/nikolai-gogol/dead-souls/d-j-hogarth(/?$|/.+?$) /ebooks/nikolai-gogol/dead-souls/c-j-hogarth$1 [R=301,L] - RewriteRule ^/ebooks/sigfrid-siwertz/downstream/macmillan-of-canada(/?$|/.+?$) /ebooks/sigfrid-siwertz/downstream/e-classen$1 [R=301,L] - RewriteRule ^/ebooks/samuel-richardson/clarissa-harlowe(/?$|/.+?$) /ebooks/samuel-richardson/clarissa$1 [R=301,L] - - # Rewrite ebooks taken down due to copyright clarifications - RewriteRule ^/ebooks/jules-verne/twenty-thousand-leagues-under-the-seas/f-p-walter.* - [R=451,L] - - # 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|avif)$ /images/covers/$1-$2$3.$4 - - RewriteRule ^/ebooks/([^\./]+?)$ /ebooks/author.php?url-path=$1 [QSA] - RewriteRule ^/ebooks/([^\./]+?)/downloads$ /bulk-downloads/get.php?author=$1 [QSA] - RewriteRule ^/ebooks/([^\./]+?)/feeds$ /feeds/get.php?author=$1 [QSA] - RewriteRule ^/subjects/([^\./]+?)$ /ebooks/index.php?tags[]=$1 [QSA] - RewriteRule ^/collections/([^\./]+?)$ /collections/get.php?collection=$1 [QSA] - RewriteRule ^/collections/([^/]+?)/downloads$ /bulk-downloads/get.php?collection=$1 - RewriteRule ^/collections/([^/]+?)/feeds$ /feeds/get.php?collection=$1 - - # Prevent this rule from firing if we're getting a distribution file - RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/downloads/.+$ - RewriteCond %{REQUEST_FILENAME} !^/ebooks/.+?/text.*$ - RewriteRule ^/ebooks/([^\.]+?)$ /ebooks/ebook.php?url-path=$1 - - # Newsletter - RewriteRule ^/newsletter$ /newsletter/subscriptions/new.php [L] - RewriteRule ^/newsletter/subscriptions/([^/\.]+?)$ /newsletter/subscriptions/get.php?uuid=$1 [L] - RewriteRule ^/newsletter/subscriptions/([^/\.]+?)/(confirm|delete)$ /newsletter/subscriptions/$2.php?uuid=$1 [L] - - # Polls - RewriteRule ^/polls/([^/\.]+)$ /polls/get.php?pollurlname=$1 [L] - RewriteRule ^/polls/([^/\.]+)/votes/new$ /polls/votes/new.php?pollurlname=$1 [L] - RewriteRule ^/polls/([^/\.]+)/votes/([0-9]+)$ /polls/votes/get.php?pollurlname=$1&userid=$2 [L] - - RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" - RewriteRule ^/polls/([^/\.]+)/votes$ /polls/votes/index.php?pollurlname=$1 [L] - - RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" - RewriteRule ^/polls/([^/\.]+)/votes$ /polls/votes/post.php?pollurlname=$1 [L] - - # Rewrite rules for feeds eeds - # Redirect old feed URLs - RewriteRule ^/(opds|rss|atom)(.*)$ /feeds/$1$2 [R=301,L] - - # If we ask for /opds/all?query=xyz, rewrite that to the search page. - RewriteCond %{QUERY_STRING} \bquery= - RewriteRule ^/feeds/(opds|atom|rss)/all.xml$ /feeds/$1/search.php [QSA] - - RewriteRule ^/feeds/(atom|rss)/([^/\.]+)$ /feeds/collection.php?type=$1&class=$2 - - RewriteRule ^/feeds/(.+\.xml)$ /feeds/download.php?path=$1 - - # Rewrite rules for bulk downloads - RewriteRule ^/bulk-downloads/(.+\.zip)$ /bulk-downloads/download.php?path=$1 - RewriteRule ^/bulk-downloads/([^/\.]+)$ /bulk-downloads/collection.php?class=$1 - - # Rewrite rules for cover art - RewriteRule ^/artworks/([^\./]+?)$ /artists/get.php?artist-url-name=$1 [L] - - RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^get$/" - RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/get.php?artist-url-name=$1&artwork-url-name=$2 [L] - - RewriteCond expr "tolower(%{REQUEST_METHOD}) =~ /^post$/" - RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)$ /artworks/post.php?artist-url-name=$1&artwork-url-name=$2 [L] - - RewriteRule ^/artworks/([^/\.]+)/([^/\.]+)/edit$ /artworks/edit.php?artist-url-name=$1&artwork-url-name=$2 [L] + Include ${conf_rewrite_root}/misc.conf + Include ${conf_rewrite_root}/feeds.conf + Include ${conf_rewrite_root}/ebooks.conf + Include ${conf_rewrite_root}/newsletters.conf + Include ${conf_rewrite_root}/artworks.conf + Include ${conf_rewrite_root}/polls.conf # Specific config for /ebooks///downloads - + # Both directives are required XSendFile on - XSendFilePath ${webroot}/www/ebooks + XSendFilePath ${web_root}/www/ebooks # Specific config for /bulk-downloads - + # Both directives are required XSendFile on - XSendFilePath ${webroot}/www/bulk-downloads + XSendFilePath ${web_root}/www/bulk-downloads # Specific config for /feeds - + # This must be defined at the top level /feeds/ directory # Both directives are required XSendFile on - XSendFilePath ${webroot}/www/feeds + XSendFilePath ${web_root}/www/feeds