How to redirect/rewrite a domain-1/dir1/dir2/* to another domain-2/dir1/dir2/* in htaccess? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern) Come Celebrate our 10 Year Anniversary!In Nginx, how can I rewrite all http requests to https while maintaining sub-domain?Redirect problem using .htaccess mod_rewrite only for root9000+ different subdomains 301 to main domain, .htacess apacheRedirect non-www ssl traffic to www ssl (apache).htaccess rewrite http to https results in loopredirect for root domain only not subdomainsrewrite rule does not rewrite url as expectedapache rewrite rules, non-www, httpsHow to 301 redirect with NginX without adding port number?Redirect all URLs without .html and set status code 301
Why does the remaining Rebel fleet at the end of Rogue One seem dramatically larger than the one in A New Hope?
How to tell that you are a giant?
Is CEO the "profession" with the most psychopaths?
Disembodied hand growing fangs
Are all finite dimensional hilbert spaces isomorphic to spaces with Euclidean norms?
What is the topology associated with the algebras for the ultrafilter monad?
Denied boarding although I have proper visa and documentation. To whom should I make a complaint?
How can I reduce the gap between left and right of cdot with a macro?
Chinese Seal on silk painting - what does it mean?
Should I follow up with an employee I believe overracted to a mistake I made?
How does the math work when buying airline miles?
How fail-safe is nr as stop bytes?
How often does castling occur in grandmaster games?
What is the appropriate index architecture when forced to implement IsDeleted (soft deletes)?
AppleTVs create a chatty alternate WiFi network
What initially awakened the Balrog?
What is this clumpy 20-30cm high yellow-flowered plant?
What is a fractional matching?
Sum letters are not two different
Why is it faster to reheat something than it is to cook it?
Can anything be seen from the center of the Boötes void? How dark would it be?
Is there a kind of relay only consumes power when switching?
Did Deadpool rescue all of the X-Force?
Why wasn't DOSKEY integrated with COMMAND.COM?
How to redirect/rewrite a domain-1/dir1/dir2/* to another domain-2/dir1/dir2/* in htaccess?
Announcing the arrival of Valued Associate #679: Cesar Manara
Planned maintenance scheduled April 23, 2019 at 00:00UTC (8:00pm US/Eastern)
Come Celebrate our 10 Year Anniversary!In Nginx, how can I rewrite all http requests to https while maintaining sub-domain?Redirect problem using .htaccess mod_rewrite only for root9000+ different subdomains 301 to main domain, .htacess apacheRedirect non-www ssl traffic to www ssl (apache).htaccess rewrite http to https results in loopredirect for root domain only not subdomainsrewrite rule does not rewrite url as expectedapache rewrite rules, non-www, httpsHow to 301 redirect with NginX without adding port number?Redirect all URLs without .html and set status code 301
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
I'm trying to redirect all URLS from one directory in one domain to the same directory to another domain on the same server, and could not make it work. How do I solve this problem?
I have tried:
Attempt 1
RewriteBase /
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
Attempt 2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
</IfModule>
Desired Output:
I'm hoping to redirect all URLS similar to these patterns:
www.domain-1.org/dir1/dir2/url-1
www.domain-1.org/dir1/dir2/url-2
www.domain-1.org/dir1/dir2/url-N
https://domain-1.org/dir1/dir2/url-1
https://domain-1.org/dir1/dir2/url-2
https://domain-1.org/dir1/dir2/url-N
http://domain-1.org/dir1/dir2/url-1
http://domain-1.org/dir1/dir2/url-2
http://domain-1.org/dir1/dir2/url-N
https://www.domain-1.org/dir1/dir2/url-1
https://www.domain-1.org/dir1/dir2/url-2
https://www.domain-1.org/dir1/dir2/url-N
http://www.domain-1.org/dir1/dir2/url-1
http://www.domain-1.org/dir1/dir2/url-2
http://www.domain-1.org/dir1/dir2/url-N
to:
https://domain-2.org/dir1/dir2/url-1
https://domain-2.org/dir1/dir2/url-2
https://domain-2.org/dir1/dir2/url-N
RegEx:
https://regex101.com/r/2BD1kB/1
.htaccess mod-rewrite redirect rewrite
add a comment |
I'm trying to redirect all URLS from one directory in one domain to the same directory to another domain on the same server, and could not make it work. How do I solve this problem?
I have tried:
Attempt 1
RewriteBase /
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
Attempt 2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
</IfModule>
Desired Output:
I'm hoping to redirect all URLS similar to these patterns:
www.domain-1.org/dir1/dir2/url-1
www.domain-1.org/dir1/dir2/url-2
www.domain-1.org/dir1/dir2/url-N
https://domain-1.org/dir1/dir2/url-1
https://domain-1.org/dir1/dir2/url-2
https://domain-1.org/dir1/dir2/url-N
http://domain-1.org/dir1/dir2/url-1
http://domain-1.org/dir1/dir2/url-2
http://domain-1.org/dir1/dir2/url-N
https://www.domain-1.org/dir1/dir2/url-1
https://www.domain-1.org/dir1/dir2/url-2
https://www.domain-1.org/dir1/dir2/url-N
http://www.domain-1.org/dir1/dir2/url-1
http://www.domain-1.org/dir1/dir2/url-2
http://www.domain-1.org/dir1/dir2/url-N
to:
https://domain-2.org/dir1/dir2/url-1
https://domain-2.org/dir1/dir2/url-2
https://domain-2.org/dir1/dir2/url-N
RegEx:
https://regex101.com/r/2BD1kB/1
.htaccess mod-rewrite redirect rewrite
add a comment |
I'm trying to redirect all URLS from one directory in one domain to the same directory to another domain on the same server, and could not make it work. How do I solve this problem?
I have tried:
Attempt 1
RewriteBase /
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
Attempt 2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
</IfModule>
Desired Output:
I'm hoping to redirect all URLS similar to these patterns:
www.domain-1.org/dir1/dir2/url-1
www.domain-1.org/dir1/dir2/url-2
www.domain-1.org/dir1/dir2/url-N
https://domain-1.org/dir1/dir2/url-1
https://domain-1.org/dir1/dir2/url-2
https://domain-1.org/dir1/dir2/url-N
http://domain-1.org/dir1/dir2/url-1
http://domain-1.org/dir1/dir2/url-2
http://domain-1.org/dir1/dir2/url-N
https://www.domain-1.org/dir1/dir2/url-1
https://www.domain-1.org/dir1/dir2/url-2
https://www.domain-1.org/dir1/dir2/url-N
http://www.domain-1.org/dir1/dir2/url-1
http://www.domain-1.org/dir1/dir2/url-2
http://www.domain-1.org/dir1/dir2/url-N
to:
https://domain-2.org/dir1/dir2/url-1
https://domain-2.org/dir1/dir2/url-2
https://domain-2.org/dir1/dir2/url-N
RegEx:
https://regex101.com/r/2BD1kB/1
.htaccess mod-rewrite redirect rewrite
I'm trying to redirect all URLS from one directory in one domain to the same directory to another domain on the same server, and could not make it work. How do I solve this problem?
I have tried:
Attempt 1
RewriteBase /
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
Attempt 2
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
</IfModule>
Desired Output:
I'm hoping to redirect all URLS similar to these patterns:
www.domain-1.org/dir1/dir2/url-1
www.domain-1.org/dir1/dir2/url-2
www.domain-1.org/dir1/dir2/url-N
https://domain-1.org/dir1/dir2/url-1
https://domain-1.org/dir1/dir2/url-2
https://domain-1.org/dir1/dir2/url-N
http://domain-1.org/dir1/dir2/url-1
http://domain-1.org/dir1/dir2/url-2
http://domain-1.org/dir1/dir2/url-N
https://www.domain-1.org/dir1/dir2/url-1
https://www.domain-1.org/dir1/dir2/url-2
https://www.domain-1.org/dir1/dir2/url-N
http://www.domain-1.org/dir1/dir2/url-1
http://www.domain-1.org/dir1/dir2/url-2
http://www.domain-1.org/dir1/dir2/url-N
to:
https://domain-2.org/dir1/dir2/url-1
https://domain-2.org/dir1/dir2/url-2
https://domain-2.org/dir1/dir2/url-N
RegEx:
https://regex101.com/r/2BD1kB/1
.htaccess mod-rewrite redirect rewrite
.htaccess mod-rewrite redirect rewrite
edited Apr 12 at 20:45
Emma
asked Apr 12 at 20:26
EmmaEmma
1067
1067
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
Assuming you have RewriteEngine On in both cases, your two "attempts" are really the same. RewriteBase is irrelevant here.
The $1 backreference refers to the captured group in the RewriteRule pattern, ie. (.*) - everything after /dir1/dir2 - so this isn't going to redirect to the "same directory" on the other domain.
Since both domains point to the same server (and I assume the same location on the filesystem) then you need to explicitly check for the domain (ie. hostname) in your redirect.
Try the following instead:
RewriteEngine On
RewriteCond %HTTP_HOST ^(www.)?domain-1.org [NC]
RewriteRule ^dir1/dir2/.* https://domain-2.org/$0 [R=302,L]
$0 is a backreference to the entire URL-path that is matched by the RewriteRule pattern. eg. dir1/dir2/url-N.
Note that this is a 302 (temporary) redirect. Test with a 302 and only change to a 301 (permanent) redirect when you have confirmed this works OK. 301s are cached persistently by the browser, so can make testing problematic.
You will need to clear your browser cache before testing.
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "2"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f962861%2fhow-to-redirect-rewrite-a-domain-1-dir1-dir2-to-another-domain-2-dir1-dir2-i%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
Assuming you have RewriteEngine On in both cases, your two "attempts" are really the same. RewriteBase is irrelevant here.
The $1 backreference refers to the captured group in the RewriteRule pattern, ie. (.*) - everything after /dir1/dir2 - so this isn't going to redirect to the "same directory" on the other domain.
Since both domains point to the same server (and I assume the same location on the filesystem) then you need to explicitly check for the domain (ie. hostname) in your redirect.
Try the following instead:
RewriteEngine On
RewriteCond %HTTP_HOST ^(www.)?domain-1.org [NC]
RewriteRule ^dir1/dir2/.* https://domain-2.org/$0 [R=302,L]
$0 is a backreference to the entire URL-path that is matched by the RewriteRule pattern. eg. dir1/dir2/url-N.
Note that this is a 302 (temporary) redirect. Test with a 302 and only change to a 301 (permanent) redirect when you have confirmed this works OK. 301s are cached persistently by the browser, so can make testing problematic.
You will need to clear your browser cache before testing.
add a comment |
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
Assuming you have RewriteEngine On in both cases, your two "attempts" are really the same. RewriteBase is irrelevant here.
The $1 backreference refers to the captured group in the RewriteRule pattern, ie. (.*) - everything after /dir1/dir2 - so this isn't going to redirect to the "same directory" on the other domain.
Since both domains point to the same server (and I assume the same location on the filesystem) then you need to explicitly check for the domain (ie. hostname) in your redirect.
Try the following instead:
RewriteEngine On
RewriteCond %HTTP_HOST ^(www.)?domain-1.org [NC]
RewriteRule ^dir1/dir2/.* https://domain-2.org/$0 [R=302,L]
$0 is a backreference to the entire URL-path that is matched by the RewriteRule pattern. eg. dir1/dir2/url-N.
Note that this is a 302 (temporary) redirect. Test with a 302 and only change to a 301 (permanent) redirect when you have confirmed this works OK. 301s are cached persistently by the browser, so can make testing problematic.
You will need to clear your browser cache before testing.
add a comment |
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
Assuming you have RewriteEngine On in both cases, your two "attempts" are really the same. RewriteBase is irrelevant here.
The $1 backreference refers to the captured group in the RewriteRule pattern, ie. (.*) - everything after /dir1/dir2 - so this isn't going to redirect to the "same directory" on the other domain.
Since both domains point to the same server (and I assume the same location on the filesystem) then you need to explicitly check for the domain (ie. hostname) in your redirect.
Try the following instead:
RewriteEngine On
RewriteCond %HTTP_HOST ^(www.)?domain-1.org [NC]
RewriteRule ^dir1/dir2/.* https://domain-2.org/$0 [R=302,L]
$0 is a backreference to the entire URL-path that is matched by the RewriteRule pattern. eg. dir1/dir2/url-N.
Note that this is a 302 (temporary) redirect. Test with a 302 and only change to a 301 (permanent) redirect when you have confirmed this works OK. 301s are cached persistently by the browser, so can make testing problematic.
You will need to clear your browser cache before testing.
RewriteRule ^dir1/dir2(.*)$ https://domain-2.org/$1 [L,R=301]
Assuming you have RewriteEngine On in both cases, your two "attempts" are really the same. RewriteBase is irrelevant here.
The $1 backreference refers to the captured group in the RewriteRule pattern, ie. (.*) - everything after /dir1/dir2 - so this isn't going to redirect to the "same directory" on the other domain.
Since both domains point to the same server (and I assume the same location on the filesystem) then you need to explicitly check for the domain (ie. hostname) in your redirect.
Try the following instead:
RewriteEngine On
RewriteCond %HTTP_HOST ^(www.)?domain-1.org [NC]
RewriteRule ^dir1/dir2/.* https://domain-2.org/$0 [R=302,L]
$0 is a backreference to the entire URL-path that is matched by the RewriteRule pattern. eg. dir1/dir2/url-N.
Note that this is a 302 (temporary) redirect. Test with a 302 and only change to a 301 (permanent) redirect when you have confirmed this works OK. 301s are cached persistently by the browser, so can make testing problematic.
You will need to clear your browser cache before testing.
answered Apr 12 at 20:54
MrWhiteMrWhite
6,38421426
6,38421426
add a comment |
add a comment |
Thanks for contributing an answer to Server Fault!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fserverfault.com%2fquestions%2f962861%2fhow-to-redirect-rewrite-a-domain-1-dir1-dir2-to-another-domain-2-dir1-dir2-i%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown