简体   繁体   中英

rewriting url in .htaccess with a wordpress

i want to change these urls on a site called https://greennutritionguides.dk . I have found out that this can be done via a rewrite in a .htaccess file. However so far i have been unsuccesful with what i have found here on stack, and other sites.

I want these urls changed:

greennutritionguides.dk/shop-4/ to greennutritionguides.dk/shop

and greennutritionguides.dk/services-2/ to greennutritionguides.dk/service

greennutritionguides.dk/member-receipes-2/ to greennutritionguides.dk/opskrifter

this site is a wordpress site and has a .htaccess file that looks like this:

## 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 /
RewriteRule ^index\.php$ - [L]

RewriteRule    ^shop-4/$    shop   

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /gdk/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /gdk/index.php [L]
</IfModule>

Put the following code in start of your .htaccess before everything else

Redirect 301 https://greennutritionguides.dk/shop-4/ https://greennutritionguides.dk/shop
Redirect 301 https://greennutritionguides.dk/services-2/ https://greennutritionguides.dk/service
Redirect 301 https://greennutritionguides.dk/member-receipes-2/ https://greennutritionguides.dk/opskrifter

Please follow steps for redirecting URLs

Step-1: Take backup of your .htaccess file

Step-2: Replace your entire .htaccess file with following code and save it.

#BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^shop-4(/.*)?$ https://greennutritionguides.dk/shop/ [L,R=301,NC]
RewriteRule ^services-2(/.*)?$ https://greennutritionguides.dk/service/ [L,R=301,NC]
RewriteRule ^member-receipes-2(/.*)?$ https://greennutritionguides.dk/opskrifter [L,R=301,NC]
RewriteBase /gdk/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /gdk/index.php [L]
</IfModule>
#END WordPress

Step-3: Clear cache of your browser and then check it.

You can refer 301 redirect not working via .htaccess within WordPress as well

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM