.htaccess - How do I redirect to a different domain AND a different folder? -


what htaccess rule need apply redirect different domain different folder structure? example: current page

http://oldwebsite.com/school/forum 

and new website be

https://newwebsite.com/forum 

i figured rewrite rule domain name alone be

rewriteengine on rewriterule ^(.*)$ https://newwebsite.com/$1 [r=301,l] 

which works fine when test it. can't find out rule i'd need rewriting old forum posts in unnecessary subfolder new domain it's directly in /forum.

also: need write https or doesn't matter , done automatically if have ssl certificate , forum (phpbb3 in case) set ssl anyway?

thanks , best regards, andi

this looking assume:

rewriteengine on rewriterule ^/?school/(.*)$ https://newwebsite.com/$1 [r=301] 

that rule work in http servers host configuration , likewise in dynamic configuration file (.htaccess) hosts document root. rewriting module must enabled. if decide use dynamic configuration file, additionally need allow using allowoverride directive.

you need specify https protocol, since redirected client make connection to. client has decide before having contact server. whether ssl certificate installed not in that. mighty rely on additional redirection http http on new domain, why? better redirect directly ssl port in first place.

and general hint: should prefer place such rules inside http servers (virtual) host configuration instead of using dynamic configuration files (.htaccess style files). files notoriously error prone, hard debug , slow down server. supported last option situations not have control on host configuration (read: cheap hosting service providers) or if have application relies on writing own rewrite rules (which obvious security nightmare).


Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -