Pointing subdomain to public_html - .htaccess

I would like to have the following:
maindomain.com pointing to public_html/subfolder
PLUS
subdomain.maindomain.com pointing to public_html
I managed to do the first on htaccess but don't know how to do the second.

Rewrite role in Apache can be helpful. take a look at the following question:
.htaccess rewrite subdomain to directory

Related

GoDaddy and .htaccess 301 redirects in subfolder

My website points to a sub-sub folder on the webroot on GoDaddy (/mywebsite/mywebsitesfolder). Apparently from my research, you cannot use a 301 redirect in an .htaccess file if it's in a subfolder of the webroot on GoDaddy. I've tried so many different things. My custom ErrorDocument statements work and bring up the error documents within this particular subfolder, of which my domain points to. What should I do to make this work aside from moving my website completely out of GoDaddy and to Bluehost?
rewriteengine on
redirect 301 /oldfile.html http://mynewsite/newfile.php
ErrorDocument 404 /.errordocs/404-missing.php
I am answering my own question here but it works like this. In order to successfully do a 301 redirect for domains pointing to subfolders on GoDaddy, you have to put the complete file path where you want the server to LOOK for the old file. I was getting confused because my old site was in a different folder and I was telling it to look in that old folder instead of the new folder I pointed the domain to. So my code would actually look like this instead of what's above in my question.
redirect 301 /mywebsitesfolder/oldfile.html http://www.newsite.com/newfile.html
No matter how many subfolders down in the webroot it is, you have to put the whole filepath. Im my case, my redirects now look like this:
redirect 301 /mywebsitesfolder/mywebsitesnewfolder/oldfile.html http://www.newsite.com/newfile.html

Subdomain Points to Subfolder and need .Htaccess to Redirect to a Wordpress Multi-Site Sub-Site

Ok, since a subdomain has to point to a real place, I created the subdomain pra.aquizone.net to point to aquizone.net/blogs/links/pra. The Wordpress (WP) Multi-site (MU) that I want to point to is aquizone.net/blogs/pra where that directory is virtually handled by the WP MU and the .htaccess under aquizone.net/blogs.
I am assuming that I can change the .htaccess file under aquizone.net/blogs/link/pra to point to aquizone.net/blogs/pra and have the subdomain wind up resulting at aquizone.net/blogs/pra. Only everything I have tried does not work. Here is my currect .htaccess file:
# Use PHP5 Single php.ini as default
AddHandler application/x-httpd-php5s .php
RewriteEngine On
RewriteRule ^pra.*$ http://aquilone.me/blogs/pra/ [R=301,L]
The AddHandler was placed there by the subdomain creation and taking it out or leaving it makes no difference. It does not work. You can go to http://aquilone.me/blogs/links/pra/ and see it does not redirect.
How can I change this to work correctly?
Well, depending on your provider, you can point your subdomain towards the same directory of your top level domain, i.e.:
example.com -> /public_html/
this.example.com -> /public_html/
But your question is not clear about what you are trying to do. Is it a subdomains network or is it a subfolders network? If subdomains, try to change the directory your subdomain points to as in the example above, and create the blog inside wp-admin/network/ If subfolders, then you don't need the subdomain, unless you really want to redirect it to a subfolder just like an easier to remember shortcut, in that case you don't need a RewriteRule, WP takes care of the virtual subfolder.
I figured out what had happened. Anything from the aquizone.net/blogs forward was being handled by Wordpress and the .htaccess setup at this subfolder. Therefore, having the redirect point to aquizone.net/blogs/links/pra and in that folder have the .htaccess to then point it where I want was never being seen.
To fix this, I moved the "links" directory to aquizone.net/links. Placing inside the ./pra/ folder with the .htaccess file. The subdomain redirects to this folder and then the .htaccess redirects this to the correct wordpress multisite subdirectory.
Of course it would be immensely easier if you could access a multisite by a hard link (for example aquizone.net/blogs/index.php?id=2) and could set the subdoman to redirect directly to that. But what I have is working.

How Change Subdomain Root Folder to Public_html via .htaccess?

I have a subdomain that I want to make the root folder to "Public_html",
for example, my root subdomain is
- /public_html/subdomain
So I want to change that path to just /public_html/ for my subdomain. I know it can be done with .htaccess, but I dont know how to do it. Thanks...
I don't know exactly what you want, but here are my two answers:
Answer 1: You want your DocumentRoot to point to public_html
In this case add/change the DocumentRoot in your (virtual) host config of your webserver (I'm assuming you're using Apache, which would be /etc/httpd/conf/httpd.conf or /etc/httpd/conf/extra/httpd-vhosts.conf or even /etc/apache2/sites-enabled/yourhost)
Answer 2: You want to redirect from your subdomain folder to the root of public_html
This is not possible via a simple RewriteRule due to the fact, that your host is pointing to the subdomain folder. The other way round would possible (redirecting from public_html to subdomain).
What you can to is to create a symbolic link from subdomain which points to public_html or a file in it - but I don't recommend this.
Furthermore resources:
A brief description on how to forward to a subfolder using Rewrite rules
Another brief description about the DocumentRoot

Which .htaccess file should I be using for 301 redirects?

This is one of those super-simple questions that I can't seem to google an answer for, so apologies in advance.
When I ftp into my (shared) server, I have a file structure like this:
Root (/)
/public_html
/newdomain.com
I had an old website that lived in /public_html, it had heaps of content and excellent SEO. We changed our name and our domain (which lives in /newdomain.com, a folder inside /public_html), and set 301 redirects from all the old content to the new website.
I tried doing this myself, but it didn't work at all, so I got my host's techsupport to do it for me. There are several .htaccess files on my server though, and I don't know which ones are actually effective and which aren't.
Root has its own .htaccess file
public_html has its own .htaccess file
/newdomain.com DOESN'T have its own .htaccess file
Redirection 1 (currently is in both root and public_html's .htaccess files, and works)
I want to redirect http://olddomain.com/whatever -> http://newdomain.com/whatever (I've currently got each individual page doing its own separate 301 versus a single rule doing this). Achieved with Redirect 301 /article-name-here/ http://www.newsite.com/article-name-here/
Redirection 2 (currently is in both root and public_html's .htaccess files, and doesn't work).
I also want to do some internal redirections of http://newdomain.com/oldpage.html -> http://newdomain.com/newpage.html. I've tried redirection public_html's .htaccess file like so:
Redirect 301 http://newsite.com/badpage.html http://newsite.com/goodpage.html
But it's not working. Do I need to set up a new .htaccess in the newsite.com folder on my server? Or am I just completely missing the mark here?
Redirection 1
To redirect everything, just remove the article name:
Redirect 301 / http://www.newsite.com/
Or if you don't want to redirect the root (i.e. requests for /), then:
RedirectMatch 301 ^/(.+)$ http://www.newsite.com/$1
Redirection 2
If the /newdomain directory is the document root for http://newdomain.com/, then you'll need to create a new htaccess file there and include:
Redirect 301 /badpage.html /goodpage.html

htaccess folder to subdomain rewrite

How can example.com/blog seamlessly show the content of blog.example.com without a redirect?
Not this:
RewriteRule ^/blog http://blog.example.com [R=301,L]
Thanks.
In order for this to occur, both the domain and subdomain would have to be running from the same directory of files. Then you could just rewrite the /blog path to the same file that the subdomain is using to run. Depending on your permissions, it could be possible to specify a ../ path to the file that it's using if you get the directories right.
However, anytime you specify a full domain path in a rewrite rule, Apache will always redirect the request. You can't get around that.
if example.com/blog and blog.example.com(subdomain) both points to same directory(blog). Then you can directly access the specified path without any redirection.

Resources