Category: geek stuff

  • How to Redirect Your Root Domain to a Specific Subdirectory in Apache

    When hosting multiple projects on a single Apache server, you may want to redirect visitors from your root domain to a specific subdirectory while keeping other projects intact. In this guide, we’ll walk you through the steps to:

    โœ… Prevent direct access to the serverโ€™s root directory
    โœ… Redirect all traffic from example.com to example.com/blog
    โœ… Ensure redirection works over both HTTP and HTTPS

    1. Understanding the Directory Structure

    Let’s say our serverโ€™s web directory is located at:

    /var/www/html/

    Inside this directory, we have multiple projects:

    /var/www/html/blog # WordPress or any main site /var/www/html/app1 # Another application /var/www/html/app2 # Another project

    We want anyone visiting example.com or 192.168.1.100 (the serverโ€™s public IP) to be automatically redirected to example.com/blog, while keeping other projects untouched.


    2. Prevent Direct Access to /var/www/html

    To prevent directory listing or direct access to /var/www/html, create or edit the .htaccess file in /var/www/html/:

    nano /var/www/html/.htaccess

    Add the following rules:

    # Disable directory listing
    Options -Indexes
    
    # Redirect root domain to /blog
    RewriteEngine On
    RewriteCond %{REQUEST_URI} ^/$
    RewriteRule ^$ /blog/ [R=301,L]

    This ensures:
    โœ… No one can list the contents of /var/www/html
    โœ… Visitors accessing example.com or 192.168.1.100 will be redirected to /blog/


    3. Configure Apache for HTTP Redirection

    Now, let’s modify Apacheโ€™s configuration for HTTP (port 80) requests.

    Edit the default virtual host file

    nano /etc/apache2/sites-available/000-default.conf

    Replace the contents with:

    <VirtualHost *:80>
        ServerAdmin webmaster@example.com
        ServerName example.com
        ServerAlias www.example.com 192.168.1.100
    
        DocumentRoot /var/www/html
    
        # Redirect root domain to /blog
        RewriteEngine On
        RewriteCond %{REQUEST_URI} ^/$
        RewriteRule ^$ /blog/ [R=301,L]
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

    4. Configure Apache for HTTPS Redirection

    If you have an SSL certificate installed, you must also configure the HTTPS (port 443) settings.

    Edit your SSL virtual host configuration

    nano /etc/apache2/sites-available/example-ssl.conf

    Modify the <VirtualHost *:443> block as follows:

    <VirtualHost *:443>
        ServerAdmin admin@example.com
        ServerName example.com
        ServerAlias www.example.com
    
        DocumentRoot /var/www/html
    
        SSLEngine on
        SSLCertificateFile /etc/letsencrypt/live/example.com/fullchain.pem
        SSLCertificateKeyFile /etc/letsencrypt/live/example.com/privkey.pem
    
        # Redirect root domain to /blog
        RewriteEngine On
        RewriteCond %{REQUEST_URI} ^/$
        RewriteRule ^$ /blog/ [R=301,L]
    
        <Directory /var/www/html>
            AllowOverride All
            Require all granted
        </Directory>
    
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>
    

    This ensures that both HTTP and HTTPS traffic are redirected correctly.


    5. Enable Apache Modules & Restart Apache

    Make sure mod_rewrite is enabled:

    a2enmod rewrite
    systemctl restart apache2

    Now, restart Apache to apply the changes:

    systemctl restart apache2

    6. Verify the Redirection

    After applying the changes, visit the following:

    โœ… http://example.com โ†’ Redirects to http://example.com/blog
    โœ… https://example.com โ†’ Redirects to https://example.com/blog
    โœ… http://192.168.1.100 โ†’ Redirects to http://192.168.1.100/blog
    โœ… https://192.168.1.100 โ†’ Redirects to https://192.168.1.100/blog


    7. Clear Cache if Redirection Doesnโ€™t Work

    If the redirection doesnโ€™t take effect immediately, try:

    systemctl restart apache2

    Final Thoughts

    With this setup, your visitors will always land on example.com/blog when accessing your root domain while keeping other projects in /var/www/html untouched.

  • Replacing ShareX with Flameshot + VPS for Private Image Uploads on Linux

    Introduction

    If you’ve used ShareX for taking screenshots and uploading them, you might have noticed a big privacy concernโ€”many image hosts (like Imgur) are public by default, and anyone with the link can access your images.

    But what if you could host your own image uploads securely, with full control, right from your Linux system?

    This guide will walk you through setting up Flameshot + VPS for private image uploads, so you get ShareX-like functionality but with total privacy.


    ๐Ÿ”น What You’ll Need

    Before we start, make sure you have:

    โœ… Linux Mint (or any Linux distro) – Weโ€™re using Linux Mint Cinnamon for this guide.
    โœ… Flameshot – A powerful screenshot tool.
    โœ… A VPS (Virtual Private Server) – To store your images privately.
    โœ… Basic command-line knowledge – To set up the script.

    ๐Ÿ”น Step 1: Setting Up Your VPS for Image Uploads

    Since we want full control, we’ll store our screenshots on a VPS instead of Imgur.

    ๐Ÿ”น Step 1: Setting Up Your VPS for Image Uploads

    Since we want full control, we’ll store our screenshots on a VPS instead of Imgur.

    1๏ธโƒฃ Create an Upload Directory

    SSH into your VPS and create a folder for uploads:

    mkdir -p /var/www/html/screenshot/public
    chmod -R 775 /var/www/html/screenshot/public
    chown -R www-data:www-data /var/www/html/screenshot/public

    2๏ธโƒฃ Create the PHP Upload Script

    Create a file upload.php inside /var/www/html/screenshot/:

    <?php
    $address = "http://your-vps-ip/screenshot/public/";
    $secret_key = "YOUR_SECRET_KEY"; // Change this to a strong password
    
    if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['image']) && isset($_POST['key'])) {
        if ($_POST['key'] !== $secret_key) {
            die("Unauthorized.");
        }
    
        $uploadDir = __DIR__ . "/public/";
        $extension = pathinfo($_FILES['image']['name'], PATHINFO_EXTENSION);
        if (!$extension) $extension = "png";
    
        $fileName = time() . "_" . uniqid() . "." . $extension;
        $targetPath = $uploadDir . $fileName;
    
        if (move_uploaded_file($_FILES['image']['tmp_name'], $targetPath)) {
            echo "$address$fileName";
        } else {
            echo "Upload failed.";
        }
    } else {
        echo "Invalid request.";
    }
    ?>

    3๏ธโƒฃ Test the Upload Script

    On your local machine, try uploading a test image:

    curl -F "image=@screenshot.png" -F "key=YOUR_SECRET_KEY" http://your-vps-ip/screenshot/upload.php

    If it returns a URL, you’re all set! ๐ŸŽ‰


    ๐Ÿ”น Step 2: Automating Flameshot to Upload Screenshots

    Now, letโ€™s configure Flameshot to automatically upload screenshots to our VPS and copy the link to the clipboard.

    1๏ธโƒฃ Create the Upload Script

    Create a new script:

    nano ~/flameshot_upload.sh

    Paste the following:

    #!/bin/bash
    
    # Capture screenshot and upload to VPS
    URL=$(flameshot gui -r | curl -s -F "image=@-" -F "key=YOUR_SECRET_KEY" http://your-vps-ip/screenshot/upload.php)
    
    # Copy the URL to clipboard and notify the user
    if [[ $URL == *"http"* ]]; then
        echo -n "$URL" | xclip -selection clipboard  # Use wl-copy if on Wayland
        notify-send "Upload Complete" "URL copied: $URL"
    else
        notify-send "Upload Failed" "$URL"
    fi

    Save and make it executable:

    chmod +x ~/flameshot_upload.sh

    Now, running ~/flameshot_upload.sh will: โœ… Let you select an area with Flameshot.
    โœ… Upload the screenshot to your VPS.
    โœ… Copy the URL to your clipboard.
    โœ… Show a desktop notification when done.


    ๐Ÿ”น Step 3: Creating a Custom Keyboard Shortcut

    To make this process seamless, let’s bind it to a hotkey (Win + Shift + U) in Linux Mint Cinnamon.

    1๏ธโƒฃ Open Keyboard Shortcuts in Cinnamon

    • Open “System Settings” โ†’ “Keyboard” โ†’ “Shortcuts”
    • Click “Add custom shortcut”
    • Name: Flameshot Auto-Upload
    • Command: ~/flameshot_upload.sh
    • Click “Add”

    2๏ธโƒฃ Assign a Keyboard Shortcut

    • Find Flameshot Auto-Upload in the list.
    • Click “Unassigned” and press Win + Shift + U.
    • Click “Apply”.

    โœ… Now, pressing Win + Shift + U will:

    • Open Flameshot to select an area.
    • Upload the screenshot to your VPS.
    • Copy the image URL automatically.
    • Notify you when the upload is done.

    ๐Ÿ”ฅ No need to manually open the terminal anymore! ๐Ÿ”ฅ


    ๐Ÿ”น Final Thoughts

    Now you have a fully private, self-hosted image uploader that replaces ShareX!

    FeatureShareXFlameshot + VPS
    PrivacyโŒ Public by defaultโœ… Private VPS storage
    Direct Linksโœ… Yesโœ… Yes
    Clipboard Auto-Copyโœ… Yesโœ… Yes
    Keyboard Shortcutโœ… Yesโœ… Yes
    Third-Party Hosting?โŒ Uses Imgurโœ… Your VPS

    ๐Ÿš€ Now, every time you screenshot, your image is privately stored and instantly copied to your clipboard!

     

error: Content is protected !!