Forum Moderators: phranque

Message Too Old, No Replies

301 htaccess redirect

         

fmosse

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

10+ Year Member



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

whitespace

6:39 pm on Sep 1, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



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?

fmosse

7:13 pm on Sep 1, 2016 (gmt 0)

10+ Year Member



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]

not2easy

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

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



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.

whitespace

10:49 pm on Sep 1, 2016 (gmt 0)

10+ Year Member Top Contributors Of The Month



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".