简体   繁体   中英

htaccess redirect from site built in a subdirectory

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 (ie 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.

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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM