2

I want to mass redirect subdirectories/subpages/pages to a single page.

from

example.com/definicje 
example.com/definicje/521/ 
example.com/definicje/592/a.html 
etc.

to a single page

example.com/single-page/

My rewrite rule actually doesn't redirect anything:

# 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]
RewriteRule ^definicje(.*)$ http://example.com/single-page/ [R=301,L]
</IfModule>
3
  • firstly don't edit the file .htaccess or the modification will be lost on next rewrite flushing. use add_rewrite_rule instead (codex.wordpress.org/Rewrite_API/add_rewrite_rule)
    – mmm
    Commented Oct 29, 2016 at 20:11
  • Thanks for the remark but I still have no idea how to write my rewriterule correctly. Help please.
    – user105919
    Commented Oct 29, 2016 at 20:20
  • have you flush the rewrite rules as written in this page ?
    – mmm
    Commented Oct 29, 2016 at 21:23

2 Answers 2

2

The solution is to put the rewriterule just after RewriteEngine On.

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^definicje(.*)$ http://example.com/single-page/ [R=301,L]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
2
  • 2
    Please provide more context to your answer. Why will this work in this situation? Provide links if possible.
    – Pat J
    Commented Oct 31, 2016 at 14:02
  • Could you edit your answer ( using the edit link above ) and provide an example please?
    – Howdy_McGee
    Commented Oct 31, 2016 at 14:38
1

There's a plugin to do redirection for all theses kinds of cases. It's simply called redirection. Search the plugin directory. I use it to redirect directories or certain pages. https://wordpress.org/plugins/redirection/

1
  • Unneeded to edit that file. Commented Apr 21, 2018 at 22:42

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.