Add htaccess for clean URLs

Also rename main files to index.php to avoid the need for custom directory indices.

Attached is a script for testing.
This commit is contained in:
2022-01-15 00:23:31 +01:00
parent 0ec0fda566
commit fc450e4984
3 changed files with 115 additions and 12 deletions

View File

@@ -1,3 +1,26 @@
ErrorDocument 404 /main.php?page=404
DirectoryIndex mainkrk.php main.php index.php start.html index.html
Options -Indexes
ErrorDocument 404 /index.php?page=404
# Redirect old URLs to new ones
RewriteCond &%{QUERY_STRING} &lang=(cs|en|de) [NC]
RewriteCond %1@&%{QUERY_STRING} (cs|en|de)@.*&page=([^&]+) [NC]
RewriteRule ^((index|mainkrk|print)\.php)?(\?.*)?$ /krk/%1/%2.html [R=301,QSD,L,nosubreq]
RewriteCond &%{QUERY_STRING} &page=([^&]+) [NC]
RewriteRule ^((index|mainkrk|print)\.php)?(\?.*)?$ /krk/%1.html [R=301,QSD,L,nosubreq]
RewriteCond &%{QUERY_STRING} &lang=(cs|en|de) [NC]
RewriteRule ^((index|mainkrk|print)\.php)?(\?.*)?$ /krk/%1/ [R=301,QSD,L,nosubreq]
# Canonization
RewriteRule ^cs(?:/(.*))?$ /krk/$1 [R=301,L]
RewriteRule ^(en|de)$ /krk/$1/ [R=301,L]
RewriteRule ^(mainkrk|index|print).php$ /krk/ [R=301,L]
### Fall back to loading pages through our “CMS”
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-f
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_URI} !-d
RewriteRule ^(en|de)/$ /krk/index.php?lang=$1 [END]
RewriteRule ^(en|de)/(.+)\.html$ /krk/index.php?page=$2&lang=$1 [END]
RewriteRule ^(.+)\.html$ /krk/index.php?page=$1 [END]
RewriteRule ^(en|de)/(.+)/$ /krk/index.php?page=$2&lang=$1 [END]
RewriteRule ^(.+)/$ /krk/index.php?page=$1 [END]