简体   繁体   English

.htaccess将所有内容从子文件夹重定向到域

[英].htaccess redirect all to domain from subfolder

I'm trying to redirect all request from my domain subfolder to another domain but don't preserve folder or querystring. 我正在尝试将所有请求从我的域子文件夹重定向到另一个域,但不保留文件夹或查询字符串。 (.htacess has to be in that subfolder folder/folder2) (.htacess必须位于该子文件夹文件夹/ folder2中)

like this: 像这样:

 http://example.com/folder/folder2/?query=test
 ->
 http://newexample.com/

all my attempts ending with redirect like this: 我所有以重定向结尾的尝试都是这样的:

 http://newexample.comfolder/folder2/?query=test

I did try this: (and more all with same result) 我确实尝试过此方法:(以及更多具有相同结果的方法)

Redirect 301 / http://newexample.com/
RewriteRule ^(.*)$ http://newexample.com/ [L,R=301]
RewriteRule ^.+$ http://newexample.com/ [R=302,NC,L]

You can just this rule in root .htaccess of old domain: 您可以在旧域的根.htaccess中使用此规则:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^(?:www\.)?example\.com$ [NC]
RewriteRule ^ http://newexample.com/? [R=302,L]

? at the end of target URL will strip off any previous query string. 目标网址的末尾将删除所有先前的查询字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM