.htaccess/DNS set folder for subdomain - .htaccess

I have a subdomain/subdirectory problem and am not sure how to solve it. I have tried different .htaccess configurations but none so far have worked.
My site is hosted on shared hosting so some limitations apply.
my directory structure, which is set up this way because of the CMS I'm using, looks like this:
assets (folder)
web (folder)
web-infiniti-brussel (folder)
.htaccess
other files and folders
My .htaccess file currently looks like this:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^gmsgroup.be$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.gmsgroup.be$
RewriteCond %{REQUEST_URI} !web/
RewriteRule (.*) /web/$1 [L]
RewriteCond %{HTTP_HOST} ^infiniti-brussel\.gmsgroup\.be
RewriteCond %{REQUEST_URI} !^/web-infiniti-brussel/
RewriteRule (.*) /web-infiniti-brussel/$1 [L]
Redirect /infiniti-brussel https://infiniti-brussel.gmsgroup.be
</IfModule>
This ends up giving me the following error: The requested URL /web-infiniti-brussel/infiniti-brussel was not found on this server.
I feel like I might be getting closer but after trying so many different things and not getting any to work I'm not sure what to do next.
I also thought I had to make a new CNAME or A record in my DNS for my subdomains but the support of my hosting said that wasn't necessary (Though they were not of any real help otherwise)
Any help or feedback would be greatly appreciated.

Related

.htaccess for multiple APIs addresses

I have a domain that hosts 3 different Wordpress pages and two different APIs.
It works more or less like this:
http://mywebsite.com (this one has a worpress in the root folder)
http://mywebsite.com/wordpress2 (another wordpress installed in this subfolder and having another domain redirecting to it
http://mywebsite.com/wordpress3 (same as above)
http://mywebsite.com/backend/domain1/api/v1
http://mywebsite.com/backend/domain2/api/v1
Now, I would like to have Rewrite rules for the API URLs so I can have:
http://mywebsite.com/domain1/api/v1
http://mywebsite.com/domain2/api/v1
While the URLs of the Worpress websites are left unaltered.
I have tried the below, but not working:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule domain1/api/v1(.*)$ backend/domain1/index.php?request=$1 [QSA,NC,L]
RewriteRule domain2/api/v1(.*)$ backend/domain2/index.php?request=$1 [QSA,NC,L]
</IfModule>
Can anyone shed some light? Thanks
My bad, all. It was not working because the httpd.conf file had the line "LoadModule rewrite_module modules/mod_rewrite.so" commented out.

Domain redirection with folder separation. htaccess

After redirecting my client domain to my server i created rewrite rule in root folder .htaccess file to point domain to a subfolder1 (joomla website):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subfolder/
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Everything worked fine but today i found out that i can access any other subfolder in my server by entering for example: myclientdomain.com/subfolder2 and what's worse google can index that and show it in search results.
If there is any way to redirect a domain in a way that I won't be able to access any other folder on my server?
I would really appreciate help as I searched throughout google for answer, my server tech support said that they don't really support these kind of problems (they only gave me a piece of code from above) and I don't really know anything about .htaccess rules and how it works.
Try this
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder\/?(.*)?$
RewriteRule ^(.*)$ /subfolder1/$1 [L]
Change above rule to:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?myclientdomain\.com$ [NC]
# if current URI is not starting with /subfolder/ then route to /subfolder/
RewriteRule ^((?!subfolder1/).*)$ subfolder1/$1 [L,NC]

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

Routing To A Folder In Cakephp's App/Webroot

I'm aware that there are a few questions on this subject already. I've trawled through them and can't make any of the proposed solutions work for me... maybe someone can help my specific problem?
I have a folder, parallax, in my app/webroot, containing index.html and associated files. This can be accessed just fine at /parallax/. However, if I try to access it at /parallax I get redirected to /app/webroot/parallax/, and ideally I'd like to suppress this behaviour.
Refactoring the whole thing as a CakePHP controller action isn't ideally something I want to get into (though if it might be simpler than I expect, let me know). The routes file doesn't as far as I know allow routing to a file in app/webroot.
The other port of call would seem to be the .htaccess file. I tried adding a rewrite rule:
RewritRule ^parallax$ parallax/index.html
or variations thereof, but the best I can get here is a page with broken images (whatever I'm ending up with, it doesn't seem to be able to find the images in the parallax/images subfolder any more).
Can anyone clear up my confusion and help me find the best route to /parallax giving the same result as /parallax/ does?
Please try the below .htaccess code in your root directory not in app directory.
<IfModule mod_rewrite.c>
RewriteEngine on
Rewriterule ^parallax/.*$ - [PT]
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
This should help you. What ever request start with parallax will be skipped by the .htaccess rule. And rest of the things will work as it is.
.htaccess root thanks to Anh Pham for this link it works perfectly http://www.balistupa.com/blog/2010/08/how-to-redirect-appwebrootblog-into-blog-wordpress-cakephp/
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_URI} !^/foldername.*
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/foldername.*
RewriteCond %{REQUEST_URI} !-d
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
I tried to reproduce the situation but its working corretly for me. I'm using cakePhp 1.3 and both urls send me to index.html:
http://localhost:5013/parallax/
http://localhost:5013/parallax
My guess is that there's something weird on your .htaccess (the one located at /app/webroot/). Mine is:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
Basically, it tells the server that if the requested url is not a file (!-f) nor a directory (!-d), it will redirect the whole url as a parameter to /webroot/index.php , so cakephp will parse the url and call the controllers and all that..
Hope this helps
You should be able to put the parallax folder with a static index.html inside the app/webroot folder and have it be accessible by default at the /parallax/ url.
If you use relative paths you can even have you img/css for that page local to the folder and skip the usual cakephp paths entirely. No htaccess needed.

htaccess redirection from domain.com to sub.domain.com while maintaining file access to folders

I'd like to redirect a website from http:// domain.com & http:// www.domain.com to http://v2.domain.com, while maintaining access to http:// (www.)domain.com/images/*
I've tried several methods but somehow I can no longer access the /images folder anymore.
P.S: both subdomain & root has different content/CMS. Any ideas as to how to implement this?
Thanks
You haven't explained exactly how these are configured. I'm going to assume that www.domain.com and v2.domain.com are different virtual hosts:
You should be able to do this in your .htaccess file or apache configuration for www.domain.com:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !images/
RewriteRule ^/(.*) http://v2.domain.com/$1 [L,R]
I realised something like this could work as well. Probably need some testing, but if this is wrong do comment.
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/images/
RewriteCond %{HTTP_HOST} !v2\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://v2.domain.com/ [R=302,L]

Resources