将多个域重定向链接到另一个域链接

时间:2017-09-14 03:53:50

标签: php .htaccess redirect

我有四个链接,我想重定向到另外四个域链接。这是链接:

1. https://example.com/book.php?bid=U0FOMDAwNzQ%2C&&dcode=ADVVV
2. https://example.com/book.php?bid=U0FOMDAwNzQ%2C&&dcode=BNMAF
3. https://example.com/book.php?bid=U0FOMDAwNzQ%2C&&dcode=DFTTW
4. https://example.com/book.php?bid=U0FOMDAwNzQ%2C&&dcode=DRETT

我想要重定向链接到:

1. https://example2.com/book/ADVVV
2. https://example2.com/book/BNMAF
3. https://example2.com/book/DFTTW
4. https://example2.com/book/DRETT

如何重定向所有链接?使用.htaccess还是其他什么?

1 个答案:

答案 0 :(得分:1)

您可以使用此.htaccess代码重定向指定的链接:

<IfModule mod_rewrite.c>

RewriteEngine On

RewriteBase /

RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteCond %{REQUEST_URI} ^/book.php$ [NC]
RewriteCond %{QUERY_STRING} ^bid=U0FOMDAwNzQ%2C&&dcode=([A-Z]+)$ [NC]
RewriteRule ^(.*)$ https://example2.com/book/%1 [R=301,L,QSD]

</IfModule>