Welcome to WebmasterWorld Guest from 35.175.191.168

Forum Moderators: Ocean10000 & phranque

Message Too Old, No Replies

301 htaccess redirect

     
5:28 pm on Sep 1, 2016 (gmt 0)

New User

5+ Year Member

joined:May 12, 2010
posts: 6
votes: 0


Hi!

I am testing a lot of options and I canīt fix it.

I must do a htaccess 301 redirect from

http://subdomain.example.com/folder
to
http://www.example.com/

and

http://subdomain.example.com/folder/anything
to
http://www.example.com/anything

How should I do it?

Thanks,
Francisco
6:39 pm on Sept 1, 2016 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 328
votes: 24


What have you tried so far?

Where does the subdomain point to on the filesystem? eg. Is it a subdirectory off the parent domains document root?
7:13 pm on Sept 1, 2016 (gmt 0)

New User

5+ Year Member

joined:May 12, 2010
posts: 6
votes: 0


RedirectMatch 301 http://subdomain.domain.com.ar/folder / http://www.newdomain.com
RedirectMatch 301 http://subdomain.domain.com.ar/folder http://www.newdomain.com
RedirectMatch 301 http://subdomain.domain.com.ar/folder (.*) http://www.newdomain.com/$1


But the home doesnīt redirect.
Links like this http://subdomain.domain.com.ar/folder/subfolder redirect perfect to http://www.newdomain.com/subfolder


But links like this http://subdomain.domain.com.ar/folder/file.php redirect to http://www.newdomain.com/folder/file.php and it should show http://www.newdomain.com/file.php


I donīt understand why.

Thanks,
Francisco

[edited by: not2easy at 7:39 pm (utc) on Sep 1, 2016]
[edit reason] removed accidental links for readability [/edit]

7:49 pm on Sept 1, 2016 (gmt 0)

Administrator from US 

WebmasterWorld Administrator not2easy is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:Dec 27, 2006
posts:4522
votes: 350


To prevent accidental links from making the post unreadable, you can enclose links within {code} and {/code} just replace the curly brackets {} with [ and ] or even easier, use the "Preview" editor next to the "Submit" button.
10:49 pm on Sept 1, 2016 (gmt 0)

Full Member

Top Contributors Of The Month

joined:Apr 11, 2015
posts: 328
votes: 24


Your initial post suggests the subdomain is on the same domain (example.com). Yet, your examples in the second post show an entirely different domain (domain.com and newdomain.com).

Assuming you are redirecting from two entirely separate domains on different file systems then you just need a single mod_alias Redirect directive in the .htaccess file at wherever "subdomain.domain.com.ar/folder/.htaccess" points to. For example:


Redirect 301 /folder http://www.newdomain.com


The Redirect directive is prefix matching, and everything after the match is passed through to the target. So "/folder/anything" will be redirected to "www.newdomain.com/anything".