How do I use the opt folder in apache? - .htaccess

I'm using htaccess to handle two domains...
If the domain is a.com use this folder for the index page
if the domain is b.com use this folder for the index page
The files or are in the opt folder
I changed sites enabled to use /opt/ directory not /var/www
Still nothing I try seems to work, it goes to /var/www and the htaccess doesn't pick up
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^(.*)$ /site/$1 [L]

Related

From domain www to no-www to subfolder

I want my domain without www always displayed, ie the URL is valid: http://miweb.net And besides this domain to point to a subdirectory and not the root directory.
How I can indicate in the htacess both conditions?
You may want to take a look at VirtualHost.
Assuming you are using Apache, this will allow you to redirect URLs with www or other sub-domains to different folders on the server.
I think I've found the solution. Apparently it works:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?myweb.net$
RewriteCond %{REQUEST_URI} !^/myweb/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /myweb/$1
RewriteCond %{HTTP_HOST} ^www\.myweb\.net$
RewriteRule ^/?$ "http\:\/\/myweb\.net\/" [R=301,L]
RewriteRule ^(/)?$ myweb/index.html [L]
If you access from a browser http://www.myweb.net, we automatically redirected to http://myweb.net (no www).
And that domain no longer points to the root directory of hosting "/ www /" if not "/ www / myweb /".

HTACCESS: mirror htdocs sub folder to www folder

Since my customers hosting providers domain cpanel doesnt have the possibility to create subdomains, I've been trying to figure out how to mirror a subfolder from my htdocs to my root www folder within my .htaccess.
Root: /domains/{domain.com}/htdocs/www/
Sub: /domains/{domain.com}/htdocs/beta/
I need to keep the subdomain {beta.domain.com} intact to let everything work as planned. So when a customer visits {www.domain.com} or {beta.domain.com} he needs to see exact the same site with the domain kept intact.
DOCUMENT_ROOT is '/etc/apache2/htdocs'
Hope someone can help me out.
This this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^beta\.domain\.com$ [NC]
RewriteRule ^/?$ /www/index.php [L]
At this moment I am helping him.
The hosting provider sucks but i can try to make it a little bit more clear.
The hosting provider build a difficult map structure but if got it, it is the following:
htdocs
domainname ----> SYMBOLIC LINK TO WWW
www
stats
If i want to add an subdomain they build the system as follow,
In the htdocs dir we should make a new map lets call it users.
We make a dir and the directory structure is as follow:
htdocs
domainname ----> SYMBOLIC LINK TO WWW
www
stats
users
Now if we go to: users.domainname.ext we will get directed to the directory users.
Note: This is the only way it's possible to make subdomains at the hosting provider.
Now what i did is add the following .htaccess file in the directory users.
RewriteEngine On
RewriteRule ^(.*)$ www.domainname.ext/ [L]
This will redirect to: www.domainname.ext
Now i added in the .htaccess of the www dir the follow:
# mod-rewrite engine
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^users\.domainname\.ext$ [NC]
RewriteRule ^(.*)$ /$1 [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
The problem is that the subdomain will redirect to the new domain, and what he want's is that url bar shows: users.domainname.ext instead of www.domainname.ext
Note: My .htaccess knowledge aint much but this is as far as i can get. So i bet i have things wrong :p in it but with this i came the farest haha.
Note 2: The part below is used for Zend Framework to work properly!
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

Links are broken when installing CakePHP on shared hosting

I have set up CakePHP on shared hosting, within a sub-directory (cakeDomain). Using htaccess in the root directory (mainDomain), I have pointed another domain to it (cakeDomain), like so:
# /.htaccess
# cakeDomain redirect rules
RedirectMatch 301 ^/cakeDomain/$ http://cakeDomain.com/
# handle domain root and skip subfolders
RewriteCond %{HTTP_HOST} cakeDomain.com
RewriteCond %{REQUEST_URI} !^/cakeDomain/
RewriteCond %{REQUEST_URI} \..+$
RewriteRule ^(.*)$ cakeDomain/$1 [L]
# add trailing slash to subfolders (eg abc to: abc/)
RewriteCond %{HTTP_HOST} cakeDomain.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} [^/]$
RewriteRule ^(.*)$ $1/ [L,R=301]
# handle files in subfolders
RewriteCond %{HTTP_HOST} cakeDomain.com
RewriteCond %{REQUEST_URI} !^/cakeDomain/
RewriteRule ^(.*)$ cakeDomain/$1/ [L]
RewriteCond %{HTTP_HOST} www.mainDomain.com/cakeDomain/
RewriteRule %{HTTP_HOST} www.cakeDomain.com [L]
Visiting mainDomain.com/cakeDomain correctly redirects you to cakeDomain.com
CakePHP's files are stored as so:
/cakeDomain/app/...
/cakeDomain/lib/...
/cakeDomain/...
etc.
Visiting cakeDomain.com brings up the correct front page but all of the links have the installed directory prepended to them:
cakeDomain.com/cakeDomain/controller/action/param1
Instead of:
cakeDomain.com/controller/action/param1
Any ideas how to fix this?
Please note, from my many searches, that it appears many people immediately suggest virtual hosts. This is not an option here; my hosting is a virtual host. I presume this solution requires htaccess and/or routing tricks. Thank-you in advance for any help you can provide.
Basically, you're putting website B (Cake) inside the public web directory of website A (Maindomain).
I would REALLY discourage you to do so because this way all 'private' CakePHP directories are also inside your public web directory (for example cakeDomain/app/tmp/logs/error.log). Please check properly if those locations are secured properly
Dou you have access to the directories 'outside' your public webfoot?
Having said that, this may be of help:
http://cookingwithcakephp.blogspot.nl/2008/04/installing-cakephp-into-subdirectory.html

Two Domains, 1 Shared Server, .htaccess file

I looked through a lot of the other "two domains, one server" questions and didn't see exactly what I'm looking for...
I have two domains, www.example1.com and www.example2.com. They are in a shared hosting environment with apache. I want:
A) example1.com to just load the normal index.html file (on a wordpress install)
B) example2.com to go to a subfolder /forums/
So, in other words, I want example1.com to be my main (normal and happy) domain and example2.com to only load up the /forums/ directory.
I'm thinking that I may only need a rewrite rule for example2.com going to /forums/?
I hope that makes sense :). Thanks so much for any help you can offer.
Try adding the following to your htaccess file in the root folder of your domain.
RewriteEngine on
RewriteBase /
#if on www.example1.com domain
RewriteCond %{HTTP_HOST} ^www\.example1\.com$ [NC]
#and not an existing file of directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#then send all requests to index.php
RewriteRule ^ index.php [L]
#if on www.example2.com domain
RewriteCond %{HTTP_HOST} ^www\.example2\.com$ [NC]
#if not already in forums directory
RewriteCond %{REQUEST_URI} !/forums/ [NC]
#rewrite requests to forums directory
RewriteRule (.*) forums/$1 [L]
Maybe it will be useful to someone. After scanning and trying various methods following seems to work perfectly. I am using Apache server. In my htaccess file, after IfModule I added <If> condition and it works fine.
<IfModule>
.
.
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
<If "%{HTTP_HOST} == 'www.xyzs.co.uk'">
Redirect permanent /xyz1 /yyy1
Redirect permanent /xyz2 /yyy2
Redirect permanent /xyz3 /yyy3
Redirect permanent /xyz4 /yyy4
<If>
More reading: http://httpd.apache.org/docs/2.4/expr.html

Check for a directory inside a subdirectory dynamically

I have a bunch of domains which points to the same directory "public_html" on my host.
There is a .htaccess file in the main folder that locally redirects each domain to a particular folder with the same name as %{HTTP_HOST} mod_rewrite variable. (eg: redirect www.domain.com to public_html/www.domain.com/)
This is the content of the .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond /%{HTTP_HOST}/#%{REQUEST_URI} !^([^#]+)#\1
RewriteRule ^(.*)$ %{HTTP_HOST}/$1 [L]
I'm having a problem when it comes to the Directory Slash directive.
If I try to access a folder in the domain url without the forward slash like http://www.domain.com/folder, the mod_dir applies the DirectorySlash and externally redirects my request to http://www.domain.com/www.domain.com/folder/
I tried applying a 301 redirect AFTER the domain directory redirect like this:
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ $1/ [R=301,L]
But for this to work, I would have to be able to check if the %{REQUEST_FILENAME} exists inside the %{HTTP_HOST} 'folder'. I even tried the following, for no success:
RewriteCond /%{HTTP_HOST}/%{REQUEST_FILENAME} -d
RewriteRule ^(.*[^/])$ $1/ [R=301,L]
How can I check, Dynamically, if the %{REQUEST_FILENAME} is a directory, which would be inside a directory with the same name as %{HTTP_HOST}?
Thanks in advance
If you work with -d you need to provide an absolute filesystem path. So try this:
RewriteCond %{DOCUMENT_ROOT}/%{HTTP_HOST}%{REQUEST_URI} -d
RewriteRule ^(.*[^/])$ $1/ [R=301,L]

Resources