Forcing www for part of my site - .htaccess

I'm trying to set up .htaccess to force www for one folder of my site, but not the rest of it. Does anyone know how to do this?

Use the solution from here:
.htaccess - how to force "www." in a generic way?
but put the .htaccess in the directory you want to force the www subdomain in. .htaccess files are only evaluated if they're in a directory that is in the directory where the file you're serving resides or any of its parent directories, so any other directories would be unaffected.
You should, however, probably not do that to begin with. Forcing the "www" subdomain is annoying enough as it is - and domains look sexier without that ;) - but only doing it for some directories is really going to confuse people.

Related

Htaccess - Disallow going backwards?

is there a way to disallow to go backwards to another directory?
E.g.: The URL is http://www.example.com/subdirectory/
If there is a HTML file which links to the the URL "/file.txt" it should not leave the subdirectory. The slash has to be ignored. Are there some Rewrite Rules in htaccess to do this? The subdirectory should be handled like a root directory.
There is a similar question here. I believe it is what you are looking for:
.htaccess. deny root, allow specific subfolder. Possible?

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.

mod_rewrite / .htaccess - domain name showing twice in URL

I have an "addon domain" with no specified htaccess file but the main site (of which the add on site is a sub dir) DOES have htaccess which rewrites url to remove the .html prefix.
Anyhow when i go to the addon domain for instance: test.com/about.html it automatically changes to test.com/test.com/about.html
Can anyone point me in the direction to correct this?
If there is no htaccess file with modRewrite in it in a directory, apache goes up to the parent directory to search for it, and this goes up along the tree (this is not affected by having an addon domain or not). So that means that your addon domain is affected by the htaccess file of the parent domain.
What you need to do is create an htaccess file in the subdirectory (the addon domain) and desactivate rewriting :
RewriteEngine Off
Or you can add your own RewriteRules if you want.

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.

Multiple htaccess files with different rewrite rules

I have 2 .htaccess files - one in root directory, another in subdirectory:
accordingly docroot/ and /subdirectory/docroot (this one works like a separate account).
The problem is that there are different rewrite rules in both files. Basicly, the problem is that the .htaccess in subdirectory doesn't work and/or is ignored.
What I am trying to achieve is to have one set of rewrite rules for docroot and other set of rewrite rules for subdirectory/docroot
edit:
the .htaccess file in subdirectory/docroot basicly strips index.php from url, and it actually works, but when i go to subdirectory/user it redirects to subdirectory/user/login (instead of subdirectory/index.php/user/login -- this parts is ok) but the website shows the root page (not subdirectory, but domain root)
Any ideas?
I just had to set RewriteBase to that particular subdirectory to make things work.

Resources