我有这个.htaccess
重定向URL与特定的关键字在URL:
RewriteEngine on
RewriteRule ^testa/(.*)$ https://app.domain2.com/testa/$1 [R=301,NC]
RewriteRule ^testb/(.*)$ https://app.domain2.com/testb/$1 [R=301,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
如果URL包含/testa/
或/testb/
,我想重定向到新的域URL:分别为https://app.domain2.com/testa/$1
和https://app.domain2.com/testb/$1
。
我有这个URL https://app.domain1.com/testa/page/1
,它应该被重定向到https://app.domain2.com/testa/page/1
。
使用上面的.htaccess
代码,我没有得到重定向结果。我想重定向URL与特定的参数名称只,而不是所有的URL从domain1到domain2。
1条答案
按热度按时间vdzxcuhz1#
您在两个重定向上缺少
L
(last
)标志。因此,处理将继续,最后一个规则将请求重写为index.php?/
,并显示错误的301 HTTP状态-由于缺少Location
标头,因此不会发生重定向。您需要在这两个规则/重定向中包含
L
标志,以便立即触发外部重定向。即[R=301,NC,L]
。如果你要重定向到目标站点的同一个URL路径(例如
testa
到testa
),那么你可以捕获整个URL路径,而不是只捕获testa
(或testb
)之后的部分。如果它只是testa
或testb
,那么你只需要一个使用正则表达式替换的规则。例如:$0
反向引用包含与RewriteRule
* 模式 * 匹配的完整URL路径。注意:首先使用302(临时)重定向进行测试,以避免潜在的缓存问题。