简体   繁体   中英

How to Blanket Redirect all URL's to Different Domain Sub-directory no Mask

.htaccess Rules

Redirect 301 "/page-1/" "https://www.newdomain.com/page-1/"
Redirect 301 "/anotherpage/run/" "https://www.newdomain.com/anotherpage/run/"
Redirect 301 "/" "https://www.newdomain.com/subdirectory/"

Current Results

The first two rules which are specific pages work well. The problem is with the catch all which will carry on the URI at the destination url. Only needing for anything other than specified URI rules to 301 to the new domain sub directory.

eg.

https://olddomain.com/page-5/ to https://www.newdomain.com/subdirectory/

Expected Results

https://olddomain.com/page-1/ redirects to https://www.newdomain.com/page-1/
https://olddomain.com/anotherpage/run/ redirects to https://www.newdomain.com/anotherpage/run/
https://olddomain.com/anypage/fun/ redirects to https://www.newdomain.com/subdirectory/

I've tried a couple Rewrite rules with no luck. It carries the complete URI to the new domain.

RewriteRule ^(.*)$ https://www.newdomain.com/subdirectory/$1 [R=301,L]

Check this rules on the top of your olddomain.com .htaccess file

<IfModule mod_rewrite.c>
    RewriteEngine On

    # custom rewrites
    RewriteRule ^page-1/$ https://www.newdomain.com/page-1/ [R=301,L]
    RewriteRule ^anotherpage/run/$ https://www.newdomain.com/anotherpage/run/ [R=301,L]

    # rewrite all not custom matched requests to https://www.newdomain.com/subdirectory/
    RewriteRule ^(.*)$ https://www.newdomain.com/subdirectory/ [R=301,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