htaccess redirect – directory and subpages to a single page

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>

2 Answers
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>

Leave a Comment