|
| 1 | +<Macro CCVHost ${host} ${proto} ${dir} ${logdir}> |
| 2 | + ServerName ${host} |
| 3 | + |
| 4 | + DocumentRoot ${dir}/docroot |
| 5 | + |
| 6 | + ErrorLog ${logdir}/error.log |
| 7 | + CustomLog ${logdir}/access.log combined |
| 8 | + |
| 9 | + #---------- |
| 10 | + # Main (general configs) |
| 11 | + #---------- |
| 12 | + |
| 13 | + # Display PHP errors to users of the staging site. |
| 14 | + php_value display_errors 1 |
| 15 | + |
| 16 | + FileETag INode MTime Size |
| 17 | + |
| 18 | + Options +ExecCGI |
| 19 | + |
| 20 | + SuexecUserGroup webadmin webadmin |
| 21 | + |
| 22 | + <Location /licenses> |
| 23 | + DirectoryIndex deed |
| 24 | + DefaultType text/html |
| 25 | + AddDefaultCharset utf-8 |
| 26 | + </Location> |
| 27 | + |
| 28 | + <Location /ccengine-fcgi> |
| 29 | + DefaultType text/html |
| 30 | + AddDefaultCharset utf-8 |
| 31 | + </Location> |
| 32 | + |
| 33 | + <Location /cc.engine-cache> |
| 34 | + DefaultType text/html |
| 35 | + AddDefaultCharset utf-8 |
| 36 | + </Location> |
| 37 | + |
| 38 | + # Always serve up deeds as text/html, even when the country code |
| 39 | + # extension makes Apache think it's something else, like .pl being |
| 40 | + # a perl script instead of Poland, but not if it's a CSS file. |
| 41 | + <LocationMatch "^/licenses/.*/deed(?!3.css).*$"> |
| 42 | + ForceType text/html |
| 43 | + </LocationMatch> |
| 44 | + |
| 45 | + <LocationMatch "^/cc.engine-cache/.*/deed.*"> |
| 46 | + ForceType text/html |
| 47 | + </LocationMatch> |
| 48 | + |
| 49 | + # We only want relative URLs to point to creativecommons.org and nothing else |
| 50 | + # like www.CC.org, etc. |
| 51 | + UseCanonicalName On |
| 52 | + |
| 53 | + # Let's have Apache set some caching options for most images on CC.org |
| 54 | + <Directory ${dir}/docroot/wp-content/uploads> |
| 55 | + ExpiresActive On |
| 56 | + ExpiresDefault A60480800 |
| 57 | + </Directory> |
| 58 | + |
| 59 | + <Directory ${dir}/docroot/images> |
| 60 | + ExpiresActive On |
| 61 | + ExpiresDefault A60480800 |
| 62 | + </Directory> |
| 63 | + |
| 64 | + DirectoryIndex index.php index.html |
| 65 | + |
| 66 | + ### ------------------------- #### |
| 67 | + ## BEGIN mod_rewrite section ## |
| 68 | + ### ------------------------- #### |
| 69 | + |
| 70 | + RewriteEngine on |
| 71 | + |
| 72 | + #---------- |
| 73 | + # Logging. Uncomment these lines and adjust the log level for debugging. Make |
| 74 | + # sure to recomment them and restart Apache when done because the file will |
| 75 | + # become immense in a hurry. |
| 76 | + #---------- |
| 77 | + |
| 78 | + #RewriteLog /tmp/rewrite.log |
| 79 | + #RewriteLogLevel 5 |
| 80 | + |
| 81 | + #---------- |
| 82 | + # Config |
| 83 | + #---------- |
| 84 | + |
| 85 | + RewriteMap uppercase int:toupper |
| 86 | + |
| 87 | + #---------- |
| 88 | + # License engine and legalcode |
| 89 | + #---------- |
| 90 | + |
| 91 | + Alias /ccengine-fcgi ${dir}/python_env/bin/ccengine.fcgi |
| 92 | + Alias /cc.engine-cache ${dir}/python_env/cache |
| 93 | + |
| 94 | + # Redirect all /license to /choose before we go any deeper |
| 95 | + RewriteRule ^/choose$ ${proto}://${host}/choose/ [L,R=301] |
| 96 | + RewriteRule ^/license$ ${proto}://${host}/choose/ [L,R=301] |
| 97 | + |
| 98 | + # Fixes this repercussions of this bug: |
| 99 | + # http://code.creativecommons.org/issues/issue898 |
| 100 | + RewriteRule ^/licenses/CC0/1.0(.*)$ /publicdomain/zero/1.0$1 [L,R=301] |
| 101 | + |
| 102 | + # Legalcode rewrites |
| 103 | + # FIXME: eval whether we should use the LHS as the actual file structure so we don't need the rewrites |
| 104 | + RewriteRule ^/legalcode ${proto}://${host}/ [L,R=301] |
| 105 | + RewriteRule .*legalcode/$ ${proto}://${host}/ [L,R=301] |
| 106 | + RewriteRule ^/licenses/(.*)sampling\+/1.0/(.*)/legalcode$ /legalcode/$1samplingplus_1.0_$2.html [L] |
| 107 | + RewriteRule ^/licenses/(.*)sampling\+/1.0/legalcode$ /legalcode/$1samplingplus_1.0.html [L] |
| 108 | + RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/(.*)/legalcode\.([A-Za-z-]+)$ /legalcode/$1_$2_$3_$4.html [L] |
| 109 | + RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/legalcode\.([a-z][a-z])$ /legalcode/$1_$2_$3.html [L] |
| 110 | + RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/(.*)/legalcode$ /legalcode/$1_$2_$3.html [L] |
| 111 | + RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/legalcode$ /legalcode/$1_$2.html [L] |
| 112 | + RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/legalcode\.txt$ /legalcode/$1_$2.txt [L] |
| 113 | + RewriteRule ^/publicdomain/(.*)/([0-9]\.[0-9])/legalcode$ /legalcode/$1_$2.html [L] |
| 114 | + RewriteRule ^/publicdomain/(.*)/([0-9]\.[0-9])/legalcode\.([a-z][a-z])$ /legalcode/$1_$2_$3.html [L] |
| 115 | + RewriteRule ^/publicdomain/(.*)/([0-9]\.[0-9])/legalcode\.txt$ /legalcode/$1_$2.txt [L] |
| 116 | + |
| 117 | + # License RDF rewrites |
| 118 | + # FIXME: eval whether we should use the LHS as the actual file structure so we don't need the rewrites |
| 119 | + RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/([a-z]+)/license_rdf$ /license_rdf/creativecommons.org_licenses_$1_$2_$3_.rdf [L,T=application/rdf+xml] |
| 120 | + RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/([a-z]+)/rdf$ /license_rdf/creativecommons.org_licenses_$1_$2_$3_.rdf [L,T=application/rdf+xml] |
| 121 | + RewriteRule ^/licenses/index.rdf$ /rdf/index.rdf [L,T=application/rdf+xml] |
| 122 | + RewriteRule ^/licenses/publicdomain/license_rdf$ /license_rdf/creativecommons.org_licenses_publicdomain_.rdf [L,T=application/rdf+xml] |
| 123 | + RewriteRule ^/licenses/publicdomain/rdf$ /license_rdf/creativecommons.org_licenses_publicdomain_.rdf [L,T=application/rdf+xml] |
| 124 | + RewriteRule ^/(publicdomain|licenses)/(.*)/([0-9]\.[0-9])/license_rdf$ /license_rdf/creativecommons.org_$1_$2_$3_.rdf [L,T=application/rdf+xml] |
| 125 | + RewriteRule ^/(publicdomain|licenses)/(.*)/([0-9]\.[0-9])/rdf$ /license_rdf/creativecommons.org_$1_$2_$3_.rdf [L,T=application/rdf+xml] |
| 126 | + RewriteRule .*rdf/$ ${proto}://${host}/ [L,R=301] |
| 127 | + |
| 128 | + # See if deed is cached before sending to cc.engine |
| 129 | + # FIXME: eval memcache as an alternative? |
| 130 | + RewriteCond %{REQUEST_URI} ^/licenses |
| 131 | + RewriteCond ${dir}/python_env/cache/%{REQUEST_FILENAME} -s |
| 132 | + RewriteRule ^/licenses/(.*) /cc.engine-cache/licenses/$1 [L,PT] |
| 133 | + |
| 134 | + # FIXME: do we really need rewrites for other licenses like GPL, etc? |
| 135 | + RewriteRule (.*)licence(.*) ${proto}://${host}$1license$2 [L,R=301] |
| 136 | + RewriteRule ^/(license|choose|characteristic|publicdomain)$ /$1/ [L,R=301] |
| 137 | + RewriteRule ^/(license|choose|characteristic|publicdomain)/(.*) /ccengine-fcgi/$1/$2 [PT,L] |
| 138 | + RewriteRule ^/licenses$ ${proto}://${host}/licenses/ [L,R=301] |
| 139 | + RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/([a-z][a-z])$ ${proto}://${host}/licenses/$1/$2/$3/ [L,R=301] |
| 140 | + RewriteRule ^/licenses/(.*)/([0-9]\.[0-9])/([Ss]cotland)$ ${proto}://${host}/licenses/$1/$2/scotland/ [L,R=301] |
| 141 | + RewriteRule ^/licenses/(.*)([0-9])$ ${proto}://${host}/licenses/$1$2/ [L,R=301] |
| 142 | + RewriteRule ^/licenses/(.*)/2.0/ar/(.*)$ ${proto}://${host}/licenses/$1/2.5/ar/$2 [L,R=301] |
| 143 | + RewriteRule ^/licenses/BSD/legalcode http://opensource.org/licenses/bsd-license.php [L,R] |
| 144 | + RewriteRule ^/licenses/by-nc-nd/2.0/deed-music$ ${proto}://${host}/licenses/by-nc-nd/2.0/ [L,R=301] |
| 145 | + RewriteRule ^/licenses/(.*)/deed.(.*)/$ ${proto}://${host}/ [L,R=301] |
| 146 | + RewriteRule ^/licenses/eldred-pd/$ http://web.archive.org/web/20030115160926/http://www.creativecommons.org/licenses/eldred-pd [L,R=301] |
| 147 | + RewriteRule ^/licenses/GPL/2.0/rdf$ http://www.gnu.org/licenses/gpl-2.0.rdf [R=301,L] |
| 148 | + RewriteRule ^/licenses/LGPL/2.1/rdf$ http://www.gnu.org/licenses/lgpl-2.1.rdf [R=301,L] |
| 149 | + RewriteRule ^/licenses/meet-the-licenses$ ${proto}://${host}/licenses/ [L,R=301] |
| 150 | + RewriteRule ^/licenses/MIT/legalcode http://opensource.org/licenses/mit-license.php [L,R] |
| 151 | + RewriteRule ^/licenses/publicdomain/1.0(.*)$ ${proto}://${host}/licenses/publicdomain/ [L,R=301] |
| 152 | + RewriteRule ^/licenses/zero/1.0/(.*) /publicdomain/zero/1.0/$1 [L,R=301] |
| 153 | + RewriteRule ^/licesne(.*)$ ${proto}://${host}/choose$1 [L,R=301] |
| 154 | + RewriteRule ^/public_domain ${proto}://${host}/publicdomain/ [R=301,L] |
| 155 | + RewriteRule ^/licenses/(.*) /ccengine-fcgi/licenses/$1 [PT,L] |
| 156 | + |
| 157 | + #---------- |
| 158 | + # Redirects to CC.net |
| 159 | + #---------- |
| 160 | + # FIXME: a bunch of these have moved / don't exist anymore |
| 161 | + |
| 162 | + RewriteRule ^/about/affiliates.*$ https://creativecommons.net/supporters [R=301,L] |
| 163 | + RewriteRule ^/about/lessigletter.*$ https://creativecommons.net/letters [L,R=301] |
| 164 | + RewriteRule ^/about/supporters$ https://creativecommons.net/supporters [L,R=301] |
| 165 | + RewriteRule ^/donate$ https://creativecommons.net/donate [R=301,L] |
| 166 | + RewriteRule /learn/aboutus/supporters$ https://creativecommons.net/supporters [R=301,L] |
| 167 | + RewriteRule ^/store$ https://creativecommons.net/store [L,R=301] |
| 168 | + RewriteRule /support/getabutton$ https://creativecommons.net/supportcc [R=301,L] |
| 169 | + RewriteRule /support/summit$ https://creativecommons.net [R=301,L] |
| 170 | + RewriteRule ^/support/?$ https://creativecommons.net/ [L,R=301] |
| 171 | + |
| 172 | + #---------- |
| 173 | + # Miscellaneous |
| 174 | + #---------- |
| 175 | + |
| 176 | + # Map backwardly named license types to their actual location |
| 177 | + RewriteRule ^/licenses/by-nc-nd/1.0/(.*)$ ${proto}://${host}/licenses/by-nd-nc/1.0/$1 [L,R=301] |
| 178 | + RewriteRule ^/licenses/by-nd-nc/2.0/(.*)$ ${proto}://${host}/licenses/by-nc-nd/2.0/$1 [L,R=301] |
| 179 | + |
| 180 | + # Map the namespace document and schema URLs |
| 181 | + # FIXME: are symlinks cleaner? |
| 182 | + RewriteRule ^/ns$ /rdf/ns.html [L] |
| 183 | + RewriteRule ^/schema.rdf$ /rdf/schema.rdf [L] |
| 184 | + |
| 185 | + #---------- |
| 186 | + # WordPress rules here instead of .htaccess |
| 187 | + #---------- |
| 188 | + |
| 189 | + # NOTE: sometimes Wordpress decides what page to display based on both the |
| 190 | + # query string AND the REQUEST_URI. mod_rewrite does not alter the |
| 191 | + # REQUEST_URI, and therefore mod_rewrite by itself is not always enough to |
| 192 | + # coerce Wordpress into doing what we want. In these case, add the query |
| 193 | + # argument '&roflcopter' to whatever RewriteRule. This will signal a special |
| 194 | + # plugin (cc_rewrite_request_uri.php) to actually alter the REQUEST_URI in the |
| 195 | + # PHP environment to be equivalent to the right side of the RewriteRule. |
| 196 | + |
| 197 | + # Catch requests to certain posts and feed them to Wordpress in a way that |
| 198 | + # it knows how to handle |
| 199 | + RewriteRule ^/weblog(/archive|)/entry/(\d+)/?$ /index.php?p=$2&%{QUERY_STRING}&roflcopter [L] |
| 200 | + RewriteRule ^/press-releases/entry/(\d+)/?$ /index.php?p=$1&roflcopter [L] |
| 201 | + |
| 202 | + # Catch any requests for the general /weblog/archive and also to the |
| 203 | + # archives for any particular year/month and then redirect the client |
| 204 | + # to the new-style permalink |
| 205 | + RewriteRule ^/weblog/archive(/?.*)$ http://${host}/weblog$1 [L,R=301] |
| 206 | + |
| 207 | + # Catch any old permalinks that point to long, ugly post names. The |
| 208 | + # CC Permalink Mapper will get this request and redirect the user accordingly. |
| 209 | + # But don't do this if someone was trying to access some particular feed |
| 210 | + RewriteCond %{REQUEST_URI} !^/([a-z-]+)/\d{4}/\d{2}/feed |
| 211 | + RewriteRule ^/([a-z-]+)/\d{4}/\d{2}/([a-zA-Z0-9-]+)/?$ /index.php?post_name=$2&category=$1&roflcopter [L] |
| 212 | + |
| 213 | + # '<some path>/rss' returns an RSS 0.92 feed, which we don't want, so make any |
| 214 | + # requests for '<some path>/rss' return an RSS 2 feed. |
| 215 | + RewriteRule ^/(.*?)rss/?$ /index.php/$1?feed=rss2 [L] |
| 216 | + |
| 217 | + # Get missing upload files from the main site |
| 218 | + # FIXME - staging only |
| 219 | + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f |
| 220 | + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d |
| 221 | + RewriteRule ^/(wp-content/uploads/.*)$ http://creativecommons.org/$1 [L] |
| 222 | + |
| 223 | + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f |
| 224 | + RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d |
| 225 | + RewriteRule . /index.php [L] |
| 226 | +</Macro> |
0 commit comments