Skip to main content

Apache httpd.conf modifications

# -- START BITNAMI CONF CHANGES --
# Make sure to add these modifications to the server's bitnami.conf file (/etc/bitnami/apache/conf/bitnami/bitnami.conf), and the bitnami-ssl.conf file. Additionally make the DocumentRoot and Directory changes to the main httpd.conf and httpd-ssl.conf files.

DocumentRoot "/opt/bitnami/apache/htdocs/public"

<Directory "/opt/bitnami/apache/htdocs/public">

AllowOverride None
Options -Indexes

# -- END BITNAMI CONF CHANGES --

## START httpd.conf MODIFICATION CHANGES --

# -- START changes to main httpd.conf area --

ErrorLog "/opt/bitnami/apache/htdocs/logs/apache_error_log"

# -- END changes to main httpd.conf area --

# -- START changes to <IfModule log_config_module> section --

CustomLog "/opt/bitnami/apache/htdocs/logs/apache_access_log" common

# -- END changes to <IfModule log_config_module> section --

# -- START changes to <Directory=/etc/bitnami/apache/htdocs/public> directory section --
# Insert the following into the aforementioned directory section:

# Stops unexpected behaviour when requesting an existing folder without a slash, e.g. https://desertedchateau.com/admin .
DirectorySlash Off

RewriteEngine on

RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=permanent,L]

# It is necessary to comment the BELOW lines when a load balancer IS in use. Otherwise we end up in an infinite HTTP => HTTPS loop.
# Load balancer directs traffic to port 80; we set it to insist on HTTP, and the above lines will force HTTPS when a load balancer is present.

RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ %{REQUEST_SCHEME}://%1%{REQUEST_URI} [R=301,L]

# Uncomment the below lines to enable maintenance mode.

#RewriteCond %{REQUEST_URI} !/maintenance(.php)?$ [NC]
#RewriteRule ^ /maintenance [R=302,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ (.*)\.php [NC]
RewriteRule ^ %1 [R=301,L]

# -- start changes for user profiles --
# First of all, redirect all "userprofile.php?username=whoever" requests to the pretty URL.
RewriteCond %{THE_REQUEST} profile/userprofile.php [NC]
RewriteCond %{QUERY_STRING} username=(.*)
RewriteRule ^.*$ /%1? [R=301,L]

# If the URL contains one slash, point the query string to the correct starting tab.
RewriteCond %{REQUEST_URI} !^/(admin|moderation|ajax|forms|css|js|profile|settings|about|account|nav|submit|search|errors|messages|notifications|articles|rules|browse|webhooks|reports)/(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/maintenance(.php)?$ [NC]
RewriteCond %{REQUEST_URI} !^/robots(.txt)?$ [NC]
RewriteRule ^([A-Za-z0-9]+)/([A-Za-z0-9]+)$ /profile/userprofile.php?username=$1&startingtab=$2 [L]

# Now, rewrite the pretty URL to the actual URL that will process the request.
# Since we don't have a / in the RewriteRule's pattern, "https://website.com/username/ will NOT work, but "https://website.com/username" will.
RewriteCond %{REQUEST_URI} !^/(admin|moderation|ajax|forms|css|js|profile|settings|about|account|nav|submit|search|errors|messages|notifications|articles|rules|browse|webhooks|reports)/(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/maintenance(.php)?$ [NC]
RewriteCond %{REQUEST_URI} !^/robots(.txt)?$ [NC]
RewriteRule ^([A-Za-z0-9]+)$ /profile/userprofile.php?username=$1 [L]

RewriteCond %{REQUEST_URI} ^/reports/$ [NC]
RewriteRule ^(.*)$ /reports/reportshome [L]

RewriteCond %{REQUEST_URI} ^/moderation/$ [NC]
RewriteRule ^(.*)$ /moderation/moderationhome [L]

RewriteCond %{REQUEST_URI} ^/admin/$ [NC]
RewriteRule ^(.*)$ /admin/adminhome [L]

RewriteCond %{REQUEST_URI} ^/settings/$ [NC]
RewriteRule ^(.*)$ /settings/account [L]

RewriteCond %{REQUEST_URI} ^/subscribe/$ [NC]
RewriteRule ^(.*)$ /subscribe/subscribehome [L]

RewriteCond %{REQUEST_URI} ^/messages/$ [NC]
RewriteRule ^(.*)$ /messages/all [L]

# -- end changes for user profiles --

RewriteCond %{THE_REQUEST} ^/artwork/displayartwork(.php)? [NC]
RewriteCond %{QUERY_STRING} artworkid=(.*)
RewriteRule ^.*$ /artwork/%1? [R=301,L]

RewriteCond %{THE_REQUEST} /artwork/([A-Za-z0-9-]*) [NC]
RewriteRule ^artwork/(.*)$ /profile/displayartwork.php?artworkid=$1 [L]

# -- start changes for private messages --

RewriteCond %{THE_REQUEST} ^/messages/all(.php)? [NC]
RewriteCond %{QUERY_STRING} threadexternalid=(.*)
RewriteRule ^.*$ /messages/%1? [R=301,L]

RewriteCond %{THE_REQUEST} /messages/([A-Za-z0-9-]*) [NC]
RewriteRule ^messages/(.*)$ /message/all.php?threadexternalid=$1 [L]

# -- end changes for private messages --

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

ErrorDocument 400 /errors/400.php
ErrorDocument 403 /errors/403.php
ErrorDocument 404 /errors/404.php
ErrorDocument 405 /errors/405.php
ErrorDocument 414 /errors/414.php
ErrorDocument 416 /errors/416.php
ErrorDocument 500 /errors/500.php
ErrorDocument 501 /errors/501.php
ErrorDocument 502 /errors/502.php
ErrorDocument 503 /errors/503.php
ErrorDocument 504 /errors/504.php

DirectoryIndex /browse/index.php

</Directory>

# -- END changes to <Directory=/etc/bitnami/apache/htdocs> directory section --

## END httpd.conf MODIFICATION CHANGES --

## START httpd.conf APPEND CHANGES --

<FilesMatch "\.(zip|rar|log)$">
    Require all denied
</FilesMatch>
<Files ".gitignore">
    Require all denied
</Files>
<Files ".gitattributes">
    Require all denied
</Files>
<Files "error_log">
    Require all denied
</Files>

## END httpd.conf APPEND CHANGES --