From 5adaffa4fcdb3f714030226694b9218eb1aaa635 Mon Sep 17 00:00:00 2001 From: zPlus <-> Date: Thu, 21 Apr 2016 14:30:58 +0200 Subject: [PATCH] .htaccess - change RewriteBase for localhost - redirect all traffic to HTTPS - remove trailing slashes - redirect old communities URLs - rewrite rss/ to rss/hot --- .gitignore | 2 +- .htaccess | 8 ++++++- .htaccess.prod | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 2 deletions(-) create mode 100755 .htaccess.prod diff --git a/.gitignore b/.gitignore index e61b0e90..e8224d5f 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ /cache/template/* -/*.prod \ No newline at end of file +*.production \ No newline at end of file diff --git a/.htaccess b/.htaccess index 84392dc1..f316a8ac 100755 --- a/.htaccess +++ b/.htaccess @@ -2,7 +2,10 @@ Options +FollowSymLinks Options -MultiViews RewriteEngine On - # RewriteBase / + RewriteBase /freepo.st/ + + # Remove trailing slashes + RewriteRule (.*)/+$ https://freepo.st/$1 [NC,R=301,QSA] # Rewrite for public assets RewriteRule .+/css/(.+)$ css/$1 [NC,L,QSA] @@ -14,6 +17,8 @@ # Redirect old urls RewriteRule community/.+/post/(.+)/.+$ post/$1 [NC,L,QSA,R=301] RewriteRule community/.+/post/(.+)/*$ post/$1 [NC,L,QSA,R=301] + # community/[community name] + RewriteRule community/.+$ / [NC,L,QSA,R=301] # Redirect /new to index.php RewriteRule ^new$ index.php?new [NC,L,QSA] @@ -32,6 +37,7 @@ # RSS RewriteRule ^rss/(.+)$ rss.php?sort=$1 [NC,L,QSA] + RewriteRule ^rss$ rss/hot [NC,L,R=301] # Rewrite to the corresponding .php page # Not a directory diff --git a/.htaccess.prod b/.htaccess.prod new file mode 100755 index 00000000..1f4250cd --- /dev/null +++ b/.htaccess.prod @@ -0,0 +1,62 @@ + + Options +FollowSymLinks + Options -MultiViews + RewriteEngine On + RewriteBase / + + # Redirect everything to HTTPS + RewriteCond %{HTTPS} off + RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] + + # Remove www + RewriteCond %{HTTP_HOST} ^www\.freepo\.st$ [NC] + RewriteRule ^(.*)$ https://freepo.st/$1 [R=301] + + # Remove trailing slashes + RewriteRule (.*)/+$ https://freepo.st/$1 [NC,R=301,QSA] + + # Rewrite for public assets + RewriteRule .+/css/(.+)$ css/$1 [NC,L,QSA] + RewriteRule .+/images/(.+)$ images/$1 [NC,L,QSA] + RewriteRule .+/javascript/(.+)$ javascript/$1 [NC,L,QSA] + + # community/[community name]/post/[post hash_id]/[post title]/comment/[comment hash_id] + RewriteRule community/.+/post/(.+)/.+/comment/(.+)$ post/$1#comment-$2 [NC,NE,L,QSA,R=301] + # Redirect old urls + RewriteRule community/.+/post/(.+)/.+$ post/$1 [NC,L,QSA,R=301] + RewriteRule community/.+/post/(.+)/*$ post/$1 [NC,L,QSA,R=301] + # community/[community name] + RewriteRule community/.+$ / [NC,L,QSA,R=301] + + # Redirect /new to index.php + RewriteRule ^new$ index.php?new [NC,L,QSA] + + # For votes from post/... + RewriteRule post/vote$ vote.php [NC,L,QSA] + + # Show a post's page + RewriteRule post/(.+)$ post.php?hash_id=$1 [NC,L,QSA] + + # Show a user's public profile + RewriteRule user/(.+)$ user.php?username=$1 [NC,L,QSA] + + # Show a user's activity (private only) + RewriteRule user_activity/(.+)$ user_activity.php?$1 [NC,L,QSA] + + # RSS + RewriteRule ^rss/(.+)$ rss.php?sort=$1 [NC,L,QSA] + RewriteRule ^rss$ rss/hot [NC,L,R=301] + + # Rewrite to the corresponding .php page + # Not a directory + RewriteCond %{REQUEST_FILENAME} !-d + # A HTML file exists + RewriteCond %{REQUEST_FILENAME}\.php -f + # Route URL to the right HTML page + RewriteRule (.+) $1.php [NC,L,QSA] + + # If the requested filename exists, simply serve it. + # We only want to let Apache serve files and not directories. + RewriteCond %{REQUEST_FILENAME} -f + RewriteRule .? - [L] + \ No newline at end of file