redirect - .htaccess file for redirecting directories of subdomain -


i have looked @ few of other .htaccess questions, none have specific usecase.

situation

i have website, example.com. has sub-domain sub.example.com. web host provides folder every sub-domain: example.com/sub

i want link both sub.example.com , example.com/sub othersite.com/some/folder/path/

what have far (the code adds www things, don't ask why, unless can fix things):

in /.htaccess:

rewritebase /  ##rewrite www options +followsymlinks rewriteengine on rewritecond %{http_host} ^example.com[nc] rewriterule ^(.*)$ http://www.example.com/$1 [r=301,nc]  ##301 redirect entire directory redirectmatch 301 /sub/(.*) https://othersite.com/some/folder/path/$1 

in /sub/.htaccess:

rewritebase /sub/  ##rewrite www options +followsymlinks rewriteengine on rewritecond %{http_host} ^sub.example.com[nc] rewriterule ^(.*)$ http://www.sub.example.com/$1 [r=301,nc]  ##301 redirect entire directory redirectmatch 301 /(.*) https://othersite.com/some/folder/path/$1 

 

the problem

when use sub.example.com/foo/bar redirect works (it redirects https://othersite.com/some/folder/path/foo/bar)

when use example.com/sub breaks (it redirects https://othersite.com/some/folder/path/sub/foo/bar, notice ../sub/..)

what need change make work sub folder isn't added path?

don't mix mod_alias rules in mod_rewrite. keep /sub/.htaccess as

##rewrite www options +followsymlinks rewriteengine on rewritebase /sub/  rewritecond %{http_host} ^sub.example.com[nc] rewriterule ^(.*)$ http://www.sub.example.com/$1 [r=301,nc]  ##301 redirect entire directory rewriterule (.*) https://othersite.com/some/folder/path/$1 [l,r=301] 

test after clearing browser cache.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -