# Triển khai lên Hostinger [Hostinger](https://hostinger.com) là nhà cung cấp shared hosting phổ biến. Hướng dẫn này nói về cách triển khai BentoPDF lên shared hosting của Hostinger. ## Yêu cầu - Gói hosting Hostinger có quyền truy cập File Manager - Đã cài Node.js trên máy để build ## Bước 1: Build dự án ```bash git clone https://github.com/alam00000/bentopdf.git cd bentopdf npm install npm run build ``` Các tệp đã build sẽ nằm trong thư mục `dist`. ## Bước 2: Tải lên Hostinger ### Triển khai trên tên miền gốc 1. Đăng nhập vào tài khoản Hostinger của bạn 2. Vào **File Manager** → **public_html** 3. **Xóa** mọi tệp hiện có (sao lưu nếu cần) 4. **Tải lên** toàn bộ nội dung thư mục `dist` trên máy của bạn vào `public_html` ### Triển khai trong thư mục con Nếu triển khai vào thư mục con (ví dụ `yourdomain.com/pdf-tools/`): 1. Build với base URL đúng: ```bash BASE_URL=/pdf-tools/ npm run build ``` 2. Tạo thư mục trong Hostinger: - Vào **File Manager** → **public_html** - Tạo thư mục mới: `pdf-tools` 3. Tải toàn bộ nội dung `dist` lên `public_html/pdf-tools/` ## Bước 3: Tạo tệp .htaccess Tạo tệp `.htaccess` ở thư mục gốc của bản triển khai (`public_html` hoặc `public_html/pdf-tools/`): ::: warning Quan trọng Với triển khai trong thư mục con, đổi `RewriteBase /` thành `RewriteBase /pdf-tools/` (hoặc tên thư mục của bạn). ::: ```apache RewriteEngine On RewriteBase / # ============================================ # 1. SECURITY HEADERS (CRITICAL FOR WASM) # ============================================ Header always set X-Frame-Options "SAMEORIGIN" Header always set X-Content-Type-Options "nosniff" Header always set X-XSS-Protection "1; mode=block" Header always set Referrer-Policy "strict-origin-when-cross-origin" Header always set Permissions-Policy "geolocation=(), microphone=(), camera=()" # REQUIRED for soffice.js (SharedArrayBuffer) Header always set Cross-Origin-Opener-Policy "same-origin" Header always set Cross-Origin-Embedder-Policy "require-corp" # ============================================ # 2. BROWSER CACHING # ============================================ ExpiresActive On ExpiresByType image/jpeg "access plus 1 year" ExpiresByType image/png "access plus 1 year" ExpiresByType image/gif "access plus 1 year" ExpiresByType image/webp "access plus 1 year" ExpiresByType image/svg+xml "access plus 1 year" ExpiresByType image/x-icon "access plus 1 year" ExpiresByType font/woff2 "access plus 1 year" ExpiresByType font/woff "access plus 1 year" ExpiresByType font/ttf "access plus 1 year" ExpiresByType text/css "access plus 1 month" ExpiresByType application/javascript "access plus 1 month" ExpiresByType application/wasm "access plus 1 year" ExpiresByType application/gzip "access plus 1 year" ExpiresByType text/html "access plus 0 seconds" # ============================================ # 3. COMPRESSION (STANDARD) # ============================================ # Prevent server from double-compressing files SetEnvIfNoCase Request_URI "\.gz$" no-gzip SetEnvIfNoCase Request_URI "\.br$" no-gzip SetEnvIfNoCase Request_URI "\.wasm$" no-gzip AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddOutputFilterByType DEFLATE application/json AddOutputFilterByType DEFLATE image/svg+xml AddOutputFilterByType DEFLATE font/woff AddOutputFilterByType DEFLATE font/ttf # ============================================ # 4. MIME TYPES & SPECIAL FILE HANDLING # ============================================ AddType application/javascript .js .mjs AddType application/wasm .wasm AddType font/woff2 .woff2 AddType font/woff .woff AddType image/webp .webp # Handle soffice.wasm.gz correctly ForceType application/wasm Header set Content-Encoding "gzip" Header set Cross-Origin-Resource-Policy "cross-origin" Header append Vary Accept-Encoding # Handle data.gz ForceType application/octet-stream Header set Content-Encoding "gzip" Header append Vary Accept-Encoding # ============================================ # 5. REDIRECTS & ROUTING # ============================================ # Canonical WWW (update domain as needed) RewriteCond %{HTTP_HOST} ^bentopdf\.com [NC] RewriteRule ^(.*)$ https://www.bentopdf.com/$1 [L,R=301] # Force HTTPS RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] # Remove trailing slash (except for language root directories) RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !^/(de|es|zh|zh-TW|vi|it|id|tr|fr|pt)/$ RewriteCond %{REQUEST_URI} (.+)/$ RewriteRule ^ %1 [R=301,L] # Existing files/dirs - serve directly RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] # ============================================ # 5.1. LANGUAGE ROUTES # ============================================ # Supported languages: de, es, zh, zh-TW, vi, it, id, tr, fr, pt # English has no prefix - served from root # English prefix redirects to root (for SEO consistency) RewriteRule ^en/?$ / [R=301,L] RewriteRule ^en/(.+)$ /$1 [R=301,L] # Language prefix root (e.g., /de/ -> /de/index.html) RewriteCond %{DOCUMENT_ROOT}/$1/index.html -f RewriteRule ^(de|es|zh|zh-TW|vi|it|id|tr|fr|pt)/?$ /$1/index.html [L] # Language prefix with path (e.g., /de/merge-pdf -> /de/merge-pdf.html) RewriteCond %{DOCUMENT_ROOT}/$1/$2.html -f RewriteRule ^(de|es|zh|zh-TW|vi|it|id|tr|fr|pt)/([^/]+)/?$ /$1/$2.html [L] # ============================================ # 5.5. DOCS ROUTING (VitePress) # ============================================ RewriteCond %{REQUEST_URI} ^/docs RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME}\.html -f RewriteRule ^(.*)$ $1.html [L] # ============================================ # 6. ADD .HTML EXTENSION IF FILE EXISTS (ROOT LEVEL ONLY) # ============================================ RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^([^/]+)$ $1.html [L] # ============================================ # 7. ERROR PAGES # ============================================ ErrorDocument 404 /404.html ``` ## Ví dụ .htaccess cho thư mục con Với `yourdomain.com/pdf-tools/`, hãy cập nhật các dòng sau: ```apache RewriteBase /pdf-tools/ # ... (same content as above, but update paths) ... # Language prefix root RewriteCond %{DOCUMENT_ROOT}/pdf-tools/$1/index.html -f RewriteRule ^(de|es|zh|zh-TW|vi|it|id|tr|fr|pt)/?$ /pdf-tools/$1/index.html [L] # Language prefix with path RewriteCond %{DOCUMENT_ROOT}/pdf-tools/$1/$2.html -f RewriteRule ^(de|es|zh|zh-TW|vi|it|id|tr|fr|pt)/([^/]+)/?$ /pdf-tools/$1/$2.html [L] # Root level .html extension RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^([^/]+)$ $1.html [L] ErrorDocument 404 /pdf-tools/404.html ``` ## Khắc phục sự cố ### Tệp WASM không tải được Đảm bảo các MIME type được đặt đúng trong `.htaccess`: ```apache AddType application/wasm .wasm ``` ### Công cụ LibreOffice không hoạt động Các header bảo mật rất quan trọng cho SharedArrayBuffer: ```apache Header always set Cross-Origin-Opener-Policy "same-origin" Header always set Cross-Origin-Embedder-Policy "require-corp" ``` Nếu các header không được áp dụng, hãy liên hệ bộ phận hỗ trợ của Hostinger để bật `mod_headers`. ### Lỗi 404 khi tải lại trang Đảm bảo quy tắc đuôi `.html` và các tuyến ngôn ngữ được cấu hình đúng. BentoPDF dùng các tệp HTML tĩnh, không dùng định tuyến SPA: ```apache # Language routes serve actual files from language directories RewriteCond %{DOCUMENT_ROOT}/$1/$2.html -f RewriteRule ^(de|es|zh|zh-TW|vi|it|id|tr|fr|pt)/([^/]+)/?$ /$1/$2.html [L] # Root level pages RewriteCond %{REQUEST_FILENAME}.html -f RewriteRule ^([^/]+)$ $1.html [L] ``` ### Giới hạn tải tệp lên Hostinger có thể giới hạn kích thước tệp. Hãy tải các tệp WASM lên riêng nếu tải hàng loạt thất bại.