diff --git a/.htaccess b/.htaccess index 5db8815..5762c3a 100644 --- a/.htaccess +++ b/.htaccess @@ -1,23 +1,13 @@ -# Enable URL rewriting RewriteEngine On -# Force HTTPS (if SSL is available) -# RewriteCond %{HTTPS} off -# RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] - -# Remove trailing slashes -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^(.*)/$ /$1 [L,R=301] - -# Remove .html extension +# Remove .html extension from URLs RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f -RewriteRule ^([^\.]+)$ $1.html [NC,L] +RewriteRule ^([^\.]+)$ $1.html [L] -# Handle SPA routing - redirect all non-file requests to index.html -RewriteCond %{REQUEST_FILENAME} !-f -RewriteCond %{REQUEST_FILENAME} !-d -RewriteRule ^(.*)$ /index.html [L] +# Redirect .html URLs to clean URLs +RewriteCond %{THE_REQUEST} /([^.]+)\.html [NC] +RewriteRule ^ /%1? [NC,L,R=301] # Handle 404 errors ErrorDocument 404 /index.html diff --git a/server.py b/server.py index fb90ad7..fd97b38 100644 --- a/server.py +++ b/server.py @@ -46,10 +46,18 @@ class CustomHTTPRequestHandler(http.server.SimpleHTTPRequestHandler): def do_GET(self): """GET 요청 처리""" + original_path = self.path + # 기본 파일 처리 if self.path == '/': self.path = '/index.html' + # .html 확장자 없이 접근 시 자동으로 .html 추가 + elif not self.path.endswith('/') and '.' not in os.path.basename(self.path): + html_path = self.path + '.html' + if os.path.exists(html_path.lstrip('/')): + self.path = html_path + super().do_GET() def log_message(self, format, *args):