pointing to a subfolder from a subdomain - .htaccess

My main site www.mysite.com is using drupal
I would like to create a WP blog at blog.mysite.com (I know I can create a blogging platform using drupal but don't wanna do that, WP is best for blogging it simply rocks)
I'm quite new to .htaccess and was wondering if there's a way to get
www.mysite.com/blog pointing to blog.mysite.com (since mysite.com/blog is better for SEO)
(but not redirecting there, it just has to load from there, so visitor sees mysite.com/blog in their browser)

If you have mod_proxy enabled, you can use the [P] flag to internally proxy www.mysite.com/blog requests to blog.mysite.com. In the htaccess file for www.mysite.com's document root (above any drupal related rules):
RewriteEngine On
RewriteRule ^/?blog/(.*)$ http://blog.mysite.com/$1 [L,P]
If you don't have mod_proxy, you may need to setup WP somewhere in the same document root as your drupal site (like in /blog/) and get wordpress to work in a subdirectory. I've had mixed results in getting that to work with another CMS so not sure how much help I can give you there.
gvanto:
Thanks. I don't have mod_proxy but I think it may cause issues having it under a subdomain and accessing in this fashion (e.g. what will all the internal links be pointing to?). The 2nd option of having it in a subfolder is probably best: http://drupal.org/node/877828

Related

Redirect old domain to new website via htaccess?

Have an old webisite (oldwebsite.com) and want to redirect all the domain requests to the new website (newwebsite.com) via htaccess (probably).
How would you go with it? Need like all old pages to redirect to the new website homepage as the structure and pages are entirely diffirent.
This probably is what you are looking for:
RewriteEngine on
RewriteRule ^ https://new.example.com%{REQUEST_URI} [QSA,R=301,END]
In general I would recommend to implement such general rules in the http server's central configuration of the host "old.example.com". You can instead use a distributed configuration file (".htaccess"), but that comes with a few small disadvantages.

Redirect all pages from old site to my blog homepage in blogger

Old and new site have different structure. Everything is differend.
I don't care about rankinks and SEO, but there are some backlinks that point there and I want to redirect them to the new site homepage. After some months I will delete the whole old site.
I just want a code for .htaccess that redirects any old site url to my new homepage blogger site. I repaeat: To NEW HOMEPAGE, not in related urls.
The old site is hosted as user in my companys domain.
http://users.company.com/myOLDname/
the new one is in google blogger
http://myNEWname.blogspot.com/
Note: If you can help, please put this above url's in the code to better understand.
Thank you.
You need something like that:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^users\.example\.com$
RewriteRule ^/?myOLDname(?:/|$) https://myNEWname.blogspot.com/ [R=301]
It is a good idea to start out with a 302 temporary redirection and only change that to a 301 permanent redirection later, once you are certain everything is correctly set up. That prevents caching issues while trying things out...
Obviously the rewriting module needs to be loaded inside the http server and enabled in the http host. In case you use a distributed configuration file you need to take care that it's interpretation is enabled at all in the host configuration and that it is located in the host's DOCUMENT_ROOT folder.
This implementation will work likewise in the http servers host configuration or inside a distributed configuration file (".htaccess" file).

Nginx URL rewrite to remove folder from URL when its followed by certain subfolders

After I have upgraded my site I see that once I go live with new version some parts of the website URLs will not be redirected for gallery, blogs and files because of new structure. And there is no way fixing it within the CMS. So my goal is to use NGINX redirects.
I wonder do any of you know any NGINX rewrite tricks to make such redirects possible?
website.com/forums/blogs/ into website.com/blogs/
website.com/forums/gallery/ into website.com/gallery/
website.com/forums/files/ into website.com/files/
I actually need the part forums dropped from the URL only and ONLY when the address is going for forums+blogs/gallery/files. Don't want to loose that google traffic.
So for example
website.com/forums/blogs/entry123/my-dog/ is redirected to
website.com/blogs/entry123/my-dog/
BUT
website.com/forums/topic/my-dog/
is left alone and working just like before because the following subfolder is neither blogs or gallery or files.
I needed that once on Apache and this one worked but on Nginx I have no idea.
RewriteRule ^forums/(blogs|gallery|files)/(.*)$ /$1/$2 [L,R=301]
You can try something like
rewrite ^/forums/(blogs|gallery|files)/(.*)$ /$1/$2;
Please note that rewrite directive accepts some flags wich meaning depends on where is it placed (is it inside a server or location block). Detailed documentation is here.

mysite.com/new redirects to mysite.com

I just rebuilt my site to be responsive with Gantry 5 and Joomla. built in inmotion hosting server. moved it into a sub domain on my real sites server, www.umiultrasound.com/new. when i try to access the site to test it redirects to www.umiultrasound.com.
I have discussed this with my host, they say i have a wildcard redirect- i don't. they say to check my .htaccess file. i did but i do not see where i am redirecting / or www.mysite.com to itself.
they then recommended that i read one of your forum results. the one they sent didn't apply to me. hoping you can help
Check for any RewriteBase command in .htaccess. You could also temporarily copy the standard htaccess.txt over .htaccess to see if this makes any difference (backup .htaccess to .htaccess.old or similar first).
Also check your configuration.php file to see if the live_site parameter has been set.

1 domain.. 2 server and 2 applications

i have a site like twitter.com on server one and on server two i have forum, which path is like domain.com/forum
on server one i wanted to implement wild card dns and put main domain on it. but on server two i wanted to keep forum separate, i cant give sub-domain forum.domain.com, because all its links are already put in search engines and link back to domain.com/forum.
so i was wondering, how can i put domain and wild card dns on server one and still able to give path on server 2 for domain.com/forum (as sub-folder).
any ideas?
do you think htaccess can do that job? if yes, then how?
You could use htaccess and mod_rewrite so domain.com/forum actually displays pages from forum.domain.com.
Maybe something like this:
Options +FollowSymLinks
RewriteEngine on
RewriteRule domain.com/forum/(.+) forum.domain.com/$1
Easy - use a proxy! If you like apache you will love apache mod_proxy for your purpose.
<VirtualHost *:80>
ServerName maindomain.com
ServerAlias *.maindomain.com
# insert document root and general settings for this domain here
# ...
ProxyPass /forum http://forumdomain.com
ProxyPassReverse /forum http://forumdomain.com
ProxyPassReverseCookieDomain forumdomain.com maindomain.com
</VirtualHost>
This configuration makes apache do a HTTP-request to your internal domain (forumdomain.com) without notifiying the users browser of the internal location. Your Forum will be accessable at http://*.yourdomain.com/forum. Cookies and headers the forum sents will get rewritten accordingly and Search-engines will not take notice of your backend-server.
You can read more about it at http://httpd.apache.org/docs/2.2/mod/mod_proxy.html
Should you need to rewrite reference sin your html (href, src ...) you might google on "mod_proxy_html".
A solution like this could of course be build with other intelligent proxyservers like squid as well. You can use it to map any content from "backend servers" to your public domain.
Make sure routing is OK or set up a host-entry for your internal domain (forumdomain) with a internet ip-addresse 192.168 ...
Enjoy your site and give feedback how worked out :)
p.s.: a "RewriteRule" directive can potentially do the same thing for you but the rdirect will be visible (and executed) by the client unless you specify the "P", foricng it to do an internal proxy request. If available I would prefer the mod_proxy though as it is more versatile and allows for more configuration.
If you use a proxy on server 1 pointing to server2, you will increase the load on server 1, since all traffic will be routed through it. Besides, if server 1 goes down, nobody will be able to reach server 2 either. Of course it is possible though, but these things are to be considered.
I would suggest setting up a supdomain for server 2 anyway, like forum.domain.com, and on server 1 you set up a 301 redirect from domain.com/forum to forum.domain.com using mod_rewrite from htaccess. Using that technique, you can even redirect calls to specific links to their corresponding page on server 2. Search engines will follow the 301 and they will eventually update the index.
You can use a 301 redirect to make sure the search engine update their index with your new urls like so:
RewriteRule domain.com/forum/(.*) http://forum.domain.com/$1 [R=301,L]
If you've got two servers you don't really have much choice but to use a redirect (ideally a 301 Permanent redirect) to move users from domain.com/forum to forum.domain.com.
The only other way to do it would be to put a reverse proxy in front of those two servers, which reads the URL and internally directs the query to the right server, but that's then an extra piece of hardware.

Resources