WordPress站点greennutritionguides.dk的.htaccess URL重写配置求助
Fixing URL Redirects for Your WordPress Site (.htaccess)
Hey there! Let's get those old URLs redirected to the new ones properly. I took a look at your current .htaccess file and spotted a couple of issues that are keeping your redirects from working:
- Your existing rewrite rule for
shop-4is missing the permanent redirect flag (R=301) and isn't positioned correctly relative to WordPress's core rewrite rules. - There's an extra
mod_rewriteblock for the/gdk/directory that doesn't seem relevant to your main site redirect needs (you can remove it unless you have a sub-site there that requires it).
Correct .htaccess Configuration
Replace your current .htaccess content with this updated version. The redirect rules are placed before WordPress's core rules, which is crucial for them to take priority:
## EXPIRES CACHING ## #<IfModule mod_expires.c> #ExpiresActive On #ExpiresByType image/jpg "access 1 year" #ExpiresByType image/jpeg "access 1 year" #ExpiresByType image/gif "access 1 year" #ExpiresByType image/png "access 1 year" #ExpiresByType text/css "access 1 month" #ExpiresByType text/html "access 1 month" #ExpiresByType application/pdf "access 1 month" #ExpiresByType text/x-javascript "access 1 month" #ExpiresByType application/x-shockwave-flash "access 1 month" #ExpiresByType image/x-icon "access 1 year" #ExpiresDefault "access 1 month" #</IfModule> ## EXPIRES CACHING ## # BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / # Add your 301 redirects HERE, before WordPress's core rules RewriteRule ^shop-4/?$ /shop [R=301,L] RewriteRule ^services-2/?$ /service [R=301,L] RewriteRule ^member-receipes-2/?$ /opskrifter [R=301,L] # WordPress core rewrite rules (leave these as-is) RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
Key Notes:
- The
R=301flag tells browsers and search engines this is a permanent redirect (great for SEO). If you're testing first, useR=302instead (temporary) and switch to 301 once you confirm everything works. - The
/?$in the rule matches both URLs with and without a trailing slash (so bothgreennutritionguides.dk/shop-4andgreennutritionguides.dk/shop-4/will redirect correctly). - Make sure your WordPress permalink settings are configured correctly (go to Settings > Permalinks in your WP admin) and that the new URLs (
/shop,/service,/opskrifter) are associated with existing pages/posts on your site. - After updating
.htaccess, clear your browser cache and test each old URL to confirm they redirect to the new ones.
内容的提问来源于stack exchange,提问作者Xzeptie
相关产品推荐
相关产品推荐

