htaccess - subfolder serve as root domain - apache

I'm using 123-reg hosting and they have main domainfeatures. Basically, it is putting your main domain (in 99% most valuable domain into root folder) with other less valuable domain in folders.
I'm looking for way to make subdomain work as root domain with .htaccess.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?functionfactory.co.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/functionfactory.co.uk/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /functionfactory.co.uk/$1
RewriteCond %{HTTP_HOST} ^(www.)?functionfactory.co.uk$ [NC]
RewriteRule ^(/)?$ functionfactory.co.uk/ [L]
I'm nearly there, it is redirecting www.functionfactory.co.uk into `functionfactory.co.uk folder, but functionfactory.co.uk/index.html isn't redirected, why?

Thanks to 123-reg support we have a solution!
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?functionfactory.co.uk$ [NC]
RewriteCond %{REQUEST_URI} !^/functionfactory.co.uk/
RewriteRule ^(.*) functionfactory.co.uk/$1

Related

.htaccess check if rewrite subdirectory exists

I want to point each subdomain to a corresponding directory by default. To make things simple subdomain and directoryname are the same. This works well but is there any way to check if the actual directory exists? If not I don't want to do the rewrite.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain.com$
RewriteCond %{REQUEST_URI} !^/%1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /%1/$1
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain.com$
RewriteRule ^(/)?$ %1/index.php [L]
You may use this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^([^.]+)\.
RewriteCond %{DOCUMENT_ROOT}/%1/index.php -f
RewriteRule ^ %1/index.php [L]
This will rewrite to a subdomain.example.com/foobar to subdomain.example.com/subdomain/index.php only if subdomain directory exists with a index.php file in it.

htaccess - Force SSL and www with Domain in Subfolder

I'm using a cPanel host, which, unfortunately, does not allow me access to Apache conf files in order to set up any VirtualHosts. I have my domain in a subfolder. I'm now also trying to force SSL as well as forcing www.
My requirements:
Domain needs to be in a subfolder, since I also have other domains
Force SSL
Force www. in the URL
The following is what I have in my .htaccess file:
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)example.com$
RewriteRule ^(/)?$ subfolder/index.php [L]
I've made various attempts that seem to get me one or two of my requirements, but not all of them at the same time.
Any help is appreciated.
I was almost there. After, the second line, I had to add a couple of RewriteConds. Not on HTTPS or, not on www:
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
The final set of rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R]
RewriteRule ^$ /subfolder/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1 [L]
Tested, and it forces SSL, and WWW in the domain, and keeps everything in the subfolder.

Redirect WWW to one subfolder and wildcard to another htaccess

I am looking to create work this Htaccess in a way that allows me to send www. to one subfolder and and any wildcard subdomains to another folder on a CentOS7 Linux server. The file structure is as follows as both subfolders have different php frameworks within them: -
.htaccess
cms (Yii)
app (Symfony)
The Htaccess File I currently have (it's been chopped around a bit) currently looks like this: -
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/cms/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /cms/public/index.php?p=$1 [QSA]
RewriteCond %{HTTP_HOST} ^(*.)?example.com$
RewriteCond %{REQUEST_URI} !^/app/web/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /app/web/$1
RewriteCond %{HTTP_HOST} ^(*.)?example.com$
RewriteRule ^(/)?$ app/web/$1 [QSA,L]
Any help of making this work would be really appreciated.

.htaccess non-www redirect to subfolder of root folder

I know this topic is discussed very frequently on the site.
But i am facing the same and cant get resolved this issue related to .htaccess reqrite.
Current scenario is I am forcing to use www. to my domain and redirect to sub-directory and use as a domain root.
I have following entry in my .htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ subfolder/index.php
All is working fine by forcing to use www. for the doamin and redirecting to sub-folder
As I have ssl certificate which is for domain.com, www.domain.com is not acceptable for ssl certificate.
Now i need non-www forcefully and redirect the primary domain to a sub-directory.
You can have it like this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(domain\.com)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1 [L]
RewriteCond %{HTTP_HOST} ^domain\.com$
RewriteRule ^(/)?$ /subfolder/index.php [L]

htaccess issue in codeigniter

I've 2 servers say x.com and x.net
x.com has CodeIgniter 1.7 and x.net has CodeIgniter 2.1
I'm using a htaccess to handle subdomain for the two servers
when I enter y.x.com it will go to x.com/y and y.x.net to x.net/y
But htaccess on the x.net server isn't working
the htaccess for x.net::
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !^index\.php
RewriteCond %{HTTP_HOST} ^(.*)\.x\.net
RewriteCond %{HTTP_HOST} !^www\.x\.net
RewriteCond %{HTTP_HOST} !^x\.net
RewriteRule ^(.*)$ %1/%{REQUEST_URI}
the htaccess for x.com is the same just the site name is different
any idea, why is this happening?
I know the CI application folder was brought out of the system folder comparing v2.0 vs. v1.7
your .htaccess is how mine looked when I was using v1.7, that is:
RewriteRule ^(.*)$ /index.php?$1 [L]
For v2.0+, my .htaccess has a couple additional directives.
Therefore, can you try adding these to your .htaccess for x.net ONLY?
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]