- 
		
hello
To change the permalink of my site from /%postname%/ to /%postname%-1/, I need a 301 redirect code and I don’t want to use a plugin.
What code should I use? 
- 
		
			
				
Hello,
Thank you for contacting Rank Math and bringing your concern to our attention.
You may try adding the following rule to your
.htaccessfile.RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_URI} !^/wp-json RewriteCond %{REQUEST_URI} !^/blog/$ RewriteCond %{REQUEST_URI} !^/category/$ RewriteRule ^(.*[^/]) /$1-1/ [L,R=301]The lines:
RewriteCond %{REQUEST_URI} !^/blog/$ RewriteCond %{REQUEST_URI} !^/category/$are the exception to your redirection rule. This means,
domain.com/blog/ordomain.com/category/won’t be redirected.However, if you have any other path to put in exclusion, you can do that by following the same method.
Or if you do not want to put any path in exclusion, you can avoid adding those lines.
Here’s how you can edit the
.htaccessfile using Rank Math:
https://rankmath.com/kb/edit-htaccess/Please do take a backup before editing your
.htaccessfile.You can also ask your hosting provider to do that for you.
Let us know how it goes. Looking forward to helping you.
Thank you.
Hello
thanks for your response
I added this code to the htaccess file, but unfortunately it didn’t work and it added a lot of 1’s to the category and content urls and the page didn’t open.Hello,
Please replace the last line of the code we shared above with the following which should only add a single
1to the destination URL:RewriteRule ^(.*[^1])$ $1-1 [L,R=301]Hope this helps solve your issues.
Don’t hesitate to get in touch if you have any other questions.
Hello
Unfortunately, it did not workHello,
Could you please share all the .htaccess codes on your site so we can check how you have set up the redirect?
You can use this tool and paste the codes in it. Once done, share the generated link here for us to check further.
Looking forward to helping you.
Thank you.
Hello
This is my .htaccess of https://ponel.ir :
`# BEGIN LSCACHE
## LITESPEED WP CACHE PLUGIN – Do not edit the contents of this block! ##<IfModule LiteSpeed>
RewriteEngine on
CacheLookup on
RewriteRule .* – [E=Cache-Control:no-autoflush]
RewriteRule \.litespeed_conf\.dat – [F,L]### marker MOBILE start ###
RewriteCond %{HTTP_USER_AGENT} Mobile|Android|Silk/|Kindle|BlackBerry|Opera\ Mini|Opera\ Mobi [NC]
RewriteRule .* – [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+ismobile]
### marker MOBILE 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 FAVICON start ###
RewriteRule favicon\.ico$ – [E=cache-control:max-age=86400]
### marker FAVICON end ###### marker WEBP start ###
RewriteCond %{HTTP_ACCEPT} “image/webp”
RewriteRule .* – [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp]
RewriteCond %{HTTP_USER_AGENT} iPhone.*Version/(\d{2}).*Safari
RewriteCond %1 >13
RewriteRule .* – [E=Cache-Control:vary=%{ENV:LSCACHE_VARY_VALUE}+webp]
### marker WEBP end ###### marker DROPQS start ###
CacheKeyModify -qs:fbclid
CacheKeyModify -qs:gclid
CacheKeyModify -qs:utm*
CacheKeyModify -qs:_ga
### marker DROPQS end ###</IfModule>
## 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! ##
### marker BROWSER CACHE start ###
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType application/pdf A31557600
ExpiresByType image/x-icon A31557600
ExpiresByType image/vnd.microsoft.icon A31557600
ExpiresByType image/svg+xml A31557600ExpiresByType image/jpg A31557600
ExpiresByType image/jpeg A31557600
ExpiresByType image/png A31557600
ExpiresByType image/gif A31557600
ExpiresByType image/webp A31557600ExpiresByType video/ogg A31557600
ExpiresByType audio/ogg A31557600
ExpiresByType video/mp4 A31557600
ExpiresByType video/webm A31557600ExpiresByType text/css A31557600
ExpiresByType text/javascript A31557600
ExpiresByType application/javascript A31557600
ExpiresByType application/x-javascript A31557600ExpiresByType application/x-font-ttf A31557600
ExpiresByType application/x-font-woff A31557600
ExpiresByType application/font-woff A31557600
ExpiresByType application/font-woff2 A31557600
ExpiresByType application/vnd.ms-fontobject A31557600
ExpiresByType font/ttf A31557600
ExpiresByType font/otf A31557600
ExpiresByType font/woff A31557600
ExpiresByType font/woff2 A31557600</IfModule>
### marker BROWSER CACHE end ##### LITESPEED WP CACHE PLUGIN – Do not edit the contents of this block! ##
# END NON_LSCACHE
# BEGIN WordPress
# دستورالعملهای (خطوط) بین “BEGIN WordPress” و “END WordPress”
# به طور پویا تولید شدهاند، و فقط باید به وسیلهٔ صافیهای وردرپرس ویرایش شوند.
# هر تغییری در دستورالعملهای بین این نشانگرها بازنویشی خواهند شد.
<IfModule mod_rewrite.c>
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]
</IfModule># END WordPress
# php — BEGIN cPanel-generated handler, do not edit
# This domain inherits the “PHP” package.
# php — END cPanel-generated handler, do not editHello,
The
.htaccessyou shared above doesn’t has the code shared by our colleague above.
Did you happen to remove it? If yes, please add the codes and share with us the final.htaccesscode.If you’re having any issues, please do let us know.
Looking forward to helping you.
Thank you
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.
 
The ticket ‘301 redirect htaccess’ is closed to new replies.