首页 > 解决方案 > htaccess 使用参数重定向到新域

问题描述

我需要通过 htaccess重定向abc.com/param到。test.bcd.com/?query=param

这是对的吗?

RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.)?test\.bcd\.com$ [NC]
RewriteRule .* http://test.bcd.com/?query=%{REQUEST_URI} [R=301,L]

标签: apache.htaccessmod-rewrite

解决方案


请试试这个

Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^query=param [NC]
RewriteCond %{HTTP_HOST} !^(www\.)?test\.bcd\.com$ [NC]
RewriteRule ^ http://test.bcd.com%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]

重定向到 index.html 然后试试这个

请添加以下两行以允许加载特定文件,以防万一还没有默认索引文件设置

Options -Indexes
DirectoryIndex index.html index.php

注意:如果你必须加载第一个 php 索引文件,那么你已经设置为

DirectoryIndex index.php index.html

推荐阅读