Question

this seems like kind of a rare situation, as i haven't been able to find a thread on it so far.

i have a wordpress site built in a subdirectory (i.e. example.com/subdir/ is the homepage).

i am now building a new site on the same domain to replace example.com/subdir/ and it will be located at example.com, in the root directory.

i need to 301 redirect all pages under example.com/subdir/folder1/ to one page at example.com/newfolder/

i don't have a lot of htaccess experience, but i expected the following htaccess file to work (i placed it in the example.com/subdir/ directory). however, it is still letting me visit example.com/subdir/folder1/ and all pages underneath it without redirecting me to example.com/newfolder/

what am i doing wrong?

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdir/index.php [L]

RedirectMatch 301 ^/folder1(.*)$ http://example.com/newfolder/
</IfModule>

i also tried it with the Redirect 301 command instead of RedirectMatch 301, and no dice.

Was it helpful?

Solution

Have 301 rules before other WP rules:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdir/

RewriteRule ^folder1(.*)$ http://example.com/newfolder/ [L,R=301]

RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdir/index.php [L]

</IfModule>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top