How to exclude subdomain from htaccess changes - php

I have this site lets say (mydomain.com) that has been running for quite a while, we decided that we would like to build a blog too, naturally we wanted to use wordpress(great for blogs). We wanted to use a subdomain blog.mydomain.com
mydomain.com uses cloudflare and the site itself is build with Laravel, our project is placed in public_html/coolproject because of laravel we had to make these changes to our htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ coolproject/public/$1 [L]
</IfModule>
After deciding to create a blog we naturally created A record in cloudflare pointing to our ip just like the main domain. (blog.mydomain.com)
The issue is following: every time we try to access blog.mydomain.com it shows mydomain.com content.
I think that the issue lies in
RewriteRule ^(.*)$ coolproject/public/$1 [L]
because every request is pointed to coolproject/public folder.
I am not very good with htaccess and don't know all of it's possibilities, I am wondering if it's possible to edit this rule so subdomains wouldn't be affected in this scenario and how.
goal is for blog.mydomain.com to show public_html/mycoolblog contents.

Related

URL Rewrite, Virtual Subdomains

Been struggling with this problem for a while now.
We have a basic online app which you can access at say
app.domain.co/signup?user=onlinestore
onlinestore is the username of the account.
We want each user to get their own subdomain that they can use the app from.
In this case the subdomain would be onlinestore.domain.co/signup and it would show them the contents as if they were here: app.domain.co/signup?user=onlinestore.
Now as well as that subdomain mirroring the login pages, when they login I would like for all of the pages inside of the app to be able to use the subdomain as well. Ideally I don't want the user to see the app.domain.co domain at all, just their personalised domain. Theres quite a number of pages inside the app so im not sure if theres a simple way for them all to be accessible from any subdomain (if logged in ofc).
Examples:
onlinestore.domain.co will become app.domain.co/signup?user=onlinestore
onlinestore.domain.co/payments will become app.domain.co/payments?user=onlinestore
onlinestore.domain.co/contact will become app.domain.co/contact?user=onlinestore
Current HTACCESS File (in the wildcard subdomain)
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.domain.co$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).domain.co
RewriteRule ^$ https://app.domain.co/signup/?user=%1 [L]
We've created a wildcard subdomain but it's not working with https, and it's doing a full redirection as opposed to a rewrite, I'm still on shared hosting so I'm not sure if I might have some restraints due to this.
Is there a simple way to do this? I don’t want the users to see the app.domain path at all, just their custom subdomain path.

How do I run a CakePHP app in a sub-folder from the root domain?

I'm trying to setup a CakePHP app in a sub-folder but run it from the root domain, eg, user requests domain.co.uk and they get the webroot at {DOCUMENT_ROOT}/version-13/app/webroot.
The hosting setup doesn't allow me to change the document root so I have the following .htaccess in the root:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ version-13/app/webroot/ [L]
RewriteRule (.*) version-13/app/webroot/$1 [L]
</IfModule>
This appears to do the job. However, Cake detects the sub-folder and adds it to all the URLs it creates (eg, $this->Form->create() actions, etc) so I end up with forms posted to domain.co.uk/version-13/signup instead of domain.co.uk/signup.
I know this is probably going to be something simple but I'm hitting a brick wall. No matter what I try I can't get it to work!
It's hard to understand your setup, you should explain it more. But if I got it right, check /app/Config/core.php:
Configure::write('App.fullBaseUrl', 'http://example.com');
Change your RewriteBase / to RewriteBase /version-13/ (in your .htaccess)and you should be set right up.
I had the exact same issue when I didn't have my local server set up correctly, which forced me to put my applications in a folder of my main domain.
Please note that you can have multiple apps at one core. This could be useful for you "versioning".
Ps. after a quick Google search I found the following. Didn't read it that well, but it looks like it does the same. http://cookingwithcakephp.blogspot.nl/2008/04/installing-cakephp-into-subdirectory.html

one subdomain as cname for another domain, can i have different custom 404 pages

Actually I have a domain - domainone.com
I have created a subdomain cname of anoter domain as
abc.domaintwo.com - CNAME as - domainone.com
so that I can use the js and css files e.g domainone.com/js/jquery.js files as abc.domaintwo.com/js/jquery.js
SO Far everything is FINE, no issues at all.
Problem:
I have a custom 404 page for domainone.com and now when that abc.domaintwo.com goes 404 same page appears which i don't want. Any help is appreciated.
Htaccess of domainone.com:
ErrorDocument 404 /404/
All i want is to have different 404 for both.....
Notes: Don't have access to shell for symlinks or alias as I am on shared hosting.
For what you are trying to do, you will need to use PHP. It cannot be done in your .htaccess. The ideal place would be the virtual hosts file, but sounds like you don't have access.
You should separate the web roots apart from each other, and then mod rewrite:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} abc.domaintwo.com$ [NC]
RewriteRule ^(js|css)/(.*) http://www.domain.com/$1/$2 [L,PT]
This should redirect http://abc.domaintwo.com/js/* and css/* to www.domain.com/js and css/
Note: it is untested, but should work if my memory serves correctly.

.htaccess method of setting a default URL to resolve to?

We have two sites, and we've just now made an in-house development server that we want to have both sites on. What I want to accomplish is to have an .htaccess in each of the site folders that prepends the development URL of the site. For example, where they simply have a header(location: /folder/whatever.php), the files should actually go to thesite/folder/whatever.php.
Currently what happens is (for example) they'll go to 192.168.x.x/folder/whatever.php
If I understood correctly and what you want is to redirect 192.168.x.x/folder/whatever.php to thesite/folder/whatever.php, you could use this:
RewriteCond %{HTTP_HOST} !^thesite.com$
RewriteRule ^(.*)$ http://thesite.com/$1 [R=301,L]

Is it possible to (virtually) move a site from www.example.org/ to www.example.org/new/ with htaccess?

I'm wondering if it is possible to upload a site to the root directory, but not make it already visible for public (and Google for SEO reasons). And what is the best way for that?
Is it possible with some rules in the .htaccess file to let it look like the site is www.example.org/new/ instead of www.example.org?
Thanks
To redirect all links to www.example.org to goto www.example.org/new add this to your .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/new/
RewriteRule ^(.*) $1 [L]
RewriteRule ^(.*)$ /new/$1 [L,R=301]
</IfModule>
I'm a bit confused by your question. You subject line seems to ask a different question to the body of the question. But if you don't want search engines to crawl your new site while you working on it add it to robots.txt (though if there is no link on your old site to the new one it should not crawl the new site anyway). And you might want to password protect it as well.
Also for SEO purposes you will not want to break links on the old site once you go live with new site. Use rewrite rules like so:
RewriteRule ^corporateplan$ /corporate-services/corporate-plan [L,R=301]
I would create a virtualhost under example.org like beta.example.org and password-protect it until the new site will launch. If everything looks fine, i would update my Apache.conf to point the new dir as DocumentRoot.
I prefer to test stuff with the definitive directory structure. That way I'm sure that nothing will break when I go live due to errors in relative or absolute paths.
If it's a brand new site, I just password protect it with Apache mod_auth_* modules. If it's a new version of an existing site, I create a new site under a subdomain.
Update
In a shared hosting environment your options are pretty limited. You have to physically upload the site in the new folder or otherwise it'll overwrite the old site. In such case, nothing special would be needed.
You may disallow robots with robots.txt. I don't know will it help you but I am using that way.

Categories