简体   繁体   中英

htaccess 301 redirect of matching string to another domain url

Am trying to redirect url of domain a to domain b, wherein redirection is done to fit in to best possible url of domain b

For ex, domain A from which 301 redirect to be done .

http://www.abc.com/blog/
http://www.abc.com/old-games?view=pages&layout=sell

There are many pgaes next to blog and many pages as sub url under old-games etc.

Domain B

http://www.xyz.com/index.php?option=com_blog&view=entry&Itemid=5
http://www.xyz.com/index.php?option=com_forms&view=pages&layout=sellgames&Itemid=10

Have tried below htaccess redirect conditions

RewriteCond %{REQUEST_URI} ^.*/blog.*$
RewriteRule .*   http://www.xyz.com/index.php?option=com_blog&view=entry&Itemid=5 [R=301,L]

RewriteCond %{REQUEST_URI} ^.*/old-games.*$
RewriteRule .*  http://www.xyz.com/index.php?option=com_forms&view=pages&layout=sellgames&Itemid=10 [R=301,L]

The redirect is happening to

 http://www.xyz.com/index.php as tested using http://htaccess.madewithlove.be/

Pl suggest for best way as if missin something in above

Thanks

Replace your code with this:

RewriteRule ^blog(/|$) http://www.xyz.com/index.php?option=com_blog&view=entry&Itemid=5 [R=301,L,QSA,NC]

RewriteRule ^old-games(/|$) http://www.xyz.com/index.php?option=com_forms&view=pages&layout=sellgames&Itemid=10 [R=301,L,NC,QSA]

Make sure to test in a different browser or clear your browser cache.

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