I got a issue with my htaccess-file. I learned a thing or two when it comes on rewriting through the htaccess-file, but this one is really keeping me awake. Hopefully one of you can help me solve with this matter. The situation is the following.
I want to redirect some specific WP blog posts (permanently) from a subdomain to some specific pages on this WP main domain subdirectory. I'm using a WP Multi subdomain website. Here's what I mean:
sub1.domain.com/postname
needs to be redirected to: domain.com/sub1/pagename
I can't figure out how to get this done. Here's how my WP htaccess- file that's located on the root of this subdomain normally looks like:
#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
<Files 403.shtml>
order allow,deny
allow from all
</Files>
I hope someone can help me with this matter. It will truly help me. Thanks in forward!
Greets, Marc
Add the following HTTP_HOST
rule just before your wordpress rules.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^postname/?$ http://domain.com/pagename [R=301,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
To redirect sub.domain.com
to domain.com/subdir
, you would use
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/subdir/$1 [R=301,L]
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.