Pagination redirect set in .htaccess file is not working

I'm trying to redirect like below but it's not working.

http://example.com/page/2 - http://example.com/item/page/2

Below is the source of .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.hogehoge\.com
RewriteRule (.*) http://hogehoge.com/$1 [R=301,L]

RewriteRule ^hogehoge.com/page/(.*)$ http://hogehoge.com/item/page/$1 [R=301,L]

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

Topic htaccess redirect Wordpress

Category Web


You need to remove the domain name from RewriteRule check. So instead of:

RewriteRule ^hogehoge.com/page/(.*)$ http://hogehoge.com/item/page/$1 [R=301,L]

You need to set:

RewriteRule ^page/(.*)$ http://hogehoge.com/item/page/$1 [R=301,L]

Also, once you have done the redirect:

  1. Make sure WordPress is responding properly to the http://example.com/item/page/1 form of URL (this is also possible by doing another internal rewrite back to http://example.com/page/1 in .htaccess or you may do that with WordPress).

  2. Clear browser cache to make sure you are not getting the cached version.

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.