2

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
1
  • Hello @himohimo - Welcome to the WordPress Development community! Could you expand on "not working" - what are the symptoms that indicate as much? Take a look at the "How to Ask" page in our help center for more tips on writing questions which are received well here =]
    – bosco
    Mar 23, 2017 at 3:42

1 Answer 1

1

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.

5
  • Thank you! I have changed the code after deleting the cache. However, it still doesn't redirect to the new page. I think something(plugin or function.php or etc) is preventing from redirecting. Are there any ways to specify it?
    – himohimo
    Mar 23, 2017 at 7:35
  • What happens when you go to this URL structure of your site directly from browser: http://hogehoge.com/item/page/1?
    – Fayaz
    Mar 23, 2017 at 10:52
  • 1
    >>Fayaz Thank you for your help! I finally managed by myself. The root cause was the pagination of the Wordpress. I changed some setting and it worked.
    – himohimo
    Mar 23, 2017 at 13:37
  • Great, I'm glad everything worked out for you :)
    – Fayaz
    Mar 23, 2017 at 13:38
  • @himohimoI'm facing the same issue. What settings you've changed in pagination?
    – chithra
    Nov 2, 2020 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.