diff --git a/scripts/install-wordpress.sh b/scripts/install-wordpress.sh index bb57134..a0f2689 100644 --- a/scripts/install-wordpress.sh +++ b/scripts/install-wordpress.sh @@ -620,6 +620,83 @@ if ! $SUDO_CMD $WP_EXECUTABLE core is-installed "${WP_RUN_ARGS[@]}"; then fi fi + # Create .htaccess file for WordPress permalink functionality + info "Creating .htaccess file for URL rewriting..." + if [[ ! -f ".htaccess" ]]; then + cat > .htaccess <<'EOF' || warning "Failed to create .htaccess file" +# BEGIN LSCACHE +## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ## + +RewriteEngine on +CacheLookup on +RewriteRule .* - [E=Cache-Control:no-autoflush] +RewriteRule litespeed/debug/.*\.log$ - [F,L] +RewriteRule \.litespeed_conf\.dat - [F,L] + +### marker ASYNC start ### +RewriteCond %{REQUEST_URI} /wp-admin/admin-ajax\.php +RewriteCond %{QUERY_STRING} action=async_litespeed +RewriteRule .* - [E=noabort:1] +### marker ASYNC end ### + +### marker CACHE RESOURCE start ### +RewriteRule wp-content/.*/[^/]*(responsive|css|js|dynamic|loader|fonts)\.php - [E=cache-control:max-age=3600] +### marker CACHE RESOURCE end ### + +### marker DROPQS start ### +CacheKeyModify -qs:fbclid +CacheKeyModify -qs:gclid +CacheKeyModify -qs:utm* +CacheKeyModify -qs:_ga +### marker DROPQS end ### + + +## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ## +# END LSCACHE +# BEGIN NON_LSCACHE +## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ## +## LITESPEED WP CACHE PLUGIN - Do not edit the contents of this block! ## +# END NON_LSCACHE + +# BEGIN WordPress +# The directives (lines) between "BEGIN WordPress" and "END WordPress" are +# dynamically generated, and should only be modified via WordPress filters. +# Any changes to the directives between these markers will be overwritten. + +RewriteEngine On +RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] +RewriteBase / +RewriteRule ^index\.php$ - [L] +RewriteCond %{REQUEST_FILENAME} !-f +RewriteCond %{REQUEST_FILENAME} !-d +RewriteRule . /index.php [L] + + +# END WordPress +# BEGIN LiteSpeed +# The directives (lines) between "BEGIN LiteSpeed" and "END LiteSpeed" are +# dynamically generated, and should only be modified via WordPress filters. +# Any changes to the directives between these markers will be overwritten. + +SetEnv noabort 1 + +# END LiteSpeed +EOF + # Set appropriate permissions for .htaccess + if [[ -f ".htaccess" ]]; then + sudo chmod 644 .htaccess + sudo chown "${WEB_USER}:${WEB_GROUP}" .htaccess + success ".htaccess file created and configured for LiteSpeed." + fi + else + info ".htaccess file already exists. Skipping creation." + fi + + # Set up pretty permalinks using WP-CLI + info "Configuring WordPress permalink structure..." + $SUDO_CMD $WP_EXECUTABLE rewrite structure '/%postname%/' "${WP_RUN_ARGS[@]}" || warning "Could not set permalink structure" + $SUDO_CMD $WP_EXECUTABLE rewrite flush "${WP_RUN_ARGS[@]}" || warning "Could not flush rewrite rules" + success "WordPress installed successfully via WP-CLI." else info "WordPress is already installed according to WP-CLI."