Make Codeigniter ignore directory - .htaccess

I have Codeigniter installed and working for my main site.
But I am now trying to add an add-on domain to the same hosting account, so I can have two sites running on the same hosting. Add-on domains make a new folder in the main public_html folder to store the web files.
How can I get Codeigniter to ignore this directory? The site doesn't load properly when I try and view it.
I have an SSL on the main site too and redirection for www URLS. Here's my .htaccess file:
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteCond %{HTTP_HOST} ^www\.mysite\.co.uk$ [NC]
RewriteRule ^(.*)$ http://mysite.co.uk/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (site|sections|here)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} onsite|sections|here)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301,L]

I have multiple domains on the same hosting two of which use CI. Don't change the main htaccess, only the one inside the folder containing the CI install. If your main site is directly in the public_html folder you may have to move it to it's own folder and redirect your URL to that folder, other than that this really shouldn't cause any issues.

Related

Change Root Folder Directory and Redirect to HTTPS with .htaccess

I don't know much about the .htaccess file and need some assistance please. I have a few websites hosted one one CPanel account. I didn't want to have my "main" site stored directly in the public_html folder, so I moved it into a subfolder and then found this .htaccess configuration that allows me to load my main site from that subdirectory. So that is working.
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change example.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/example_directory/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /example.com/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by / then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example.com/index.html
So as I said, the above .htaccess will allow me to store my site files in a different folder rather than right at the root. But now I'm trying to force a redirect for this site over https as well. I found this site here:
Force Website to Use SSL
But, since I really don't understand the .htaccess file I'm having trouble integrating these two features together. Any help on this would be greatly appreciated. Thanks.
I'm pretty certain I figured this out myself. I just simply had to add this to the end of my .htaccess file:
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
and it works like a charm. Full .htaccess file looks like this, which changes the folder directory for the site to use and then forces it over https.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/example_directory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /example.com/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ example.com/index.html
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}

Laravel 5 shared host subdomain htaccess

Firstly because im on a shared host I cannot place contents of my public folder directly into root. I have to place the entire project into the public_html directory and use a .htaccess to point to the public folder like below (which works fine for a single Laravel project):
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
I now created a subdomain with the host and it created a directory inside my public_html directory called store.domain.com. This will be for an entirely different Laravel project. If I place the regular folder structure with the .htaccess file into this subdomain folder I get a 503 error when accessing the subdomain. I spoke to the host and when they suggested removing the root .htaccess file the subdomain started working but the main domain fell over.
Ive been struggling for days now reading up various solutions to other peoples similar issues on WordPress but cannot get anything to work correctly. The solution below sort-of works but it keeps adding on the public folder to my URL for the subdomain (root domain project is working fine):
RewriteBase /
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} ^store.mc.com
RewriteRule ^(.*)$ /public/$1 [L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{HTTP_HOST} !^store.mc.com$
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ /public/$1 [L]
Anyone had this issue or know how to solve it?
I dont really understand why this works but the below fixed my issue:
RewriteBase /
RewriteCond %{HTTP_HOST} !^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTP_HOST} ^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
I uploaded my website files to a subdomain, and I always see this error
You don't have permission to access this resource. Additionally, a 403
Forbidden error was encountered while trying to use an ErrorDocument to handle the request.
Just create a file .htaccess In the subdomain folder
Add this to it and save .
RewriteBase /
RewriteCond %{HTTP_HOST} !^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/$1 [L]
RewriteCond %{HTTP_HOST} ^subdomain
RewriteCond %{REQUEST_URI} !^public
RewriteRule ^(.*)$ public/ [L]
Your RewriteCond is invalid without the leading slash.
change :
RewriteCond %{REQUEST_URI} !^public
to
RewriteCond %{REQUEST_URI} !^/public

.htaccess multiple rules redirect to different folder

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
RewriteCond %{REQUEST_URI} !^/drupal/
RewriteRule ^(.*)$ /drupal/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
The folder structure is as follows
public_html
/apps
/drupal
Currently when we give www.domainname.com it redirects to drupal folder and our website is displayed. We have some apps installed in apps folder and want to access it using the url www.domainname.com/apps and when we give this it goes to drupal framework and we get page not found.
What rule should we write to that when we give /apps in the url it should get into apps folder and all other times it should go to drupal folder.
Any help is appreciated. Thanks.
It looks like you're missing a line in the rewrite rules that you posted, but you just need to exclude the apps folder the same way you are excluding the drupal folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domainname.com$
RewriteCond %{REQUEST_URI} !^/drupal/
RewriteCond %{REQUEST_URI} !^/apps/
RewriteRule ^(.*)$ /drupal/$1 [L]

htaccess - hosting multiple domains on one shared server,

I have a site1.com as my primary site. I created two folders in the root directory "site1" & "site2". I used Htaccess to redirect site1.com's traffic to folder "site1". Site2 works too as site2.com using directory "site2".
Now, the issue is because site1 is primary, I'm able to visit site2 via site.com/site2 . What rewrite can I use to ignore site.com/site2, or show a 404 when site1.com/site2 is visited and still allow for site2.com to work?
Here is my htaccess file.
RewriteEngine on
Options -MultiViews
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteCond %{REQUEST_URI} !^/site1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /site1/$1
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^(/)?$ site1/index.php [L]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
My folder hierarchy is
-root
.htaccess
-site1 folder
- index.php
-site2 folder
- index.php
Due to godaddy's primary domain setup, even though when i visit site.com it loads info from site1 folder, if i visit site1.com/site2 it will load site 2
I went in a different direction for a similar problem on Godaddy.
Rather than looking for just hits from site1.com and redirect them, I sent any requests hitting the site2 subfolder / subdomain to site2.com with this:
RewriteCond %{HTTP_HOST} !^site2\.com$ [NC]
RewriteRule ^(.*)$ http://site2.com/$1 [R=301,L]
Now any requests that worm their way into that site1.com/site2 subfolder get 301'd to the appropriate page on site2.
I don't consider myself an expert by a longshot and would welcome critiques from those with more experience.
Untested code: I believe you can do the following
RewriteCond %{HTTP_HOST} ^(www.)?site1.com$
RewriteRule ^site2/(.*)$ http://site1.com/$1 [R=301]
This will (or should) redirect the client from http://site1.com/site2/my/awesome/page.php to http://site2.com/my/awesome/page.php.

htaccess rewrite rules for multiple domains (symfony 2 in subfolders)

straight to the point.
I have a web hosting with 2 domains pointing to the root directory of the hosting.
I have 2 seperate projects in the root directory both symfony2
I need to redirect the domains to the seperate directories using .htaccess.
My current .htaccess file in the root folder
RewriteEngine On
#www to non www
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301, L]
#domain1
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/domain1/web
RewriteRule ^(.*) /domain1/web$1 [L]
#domain2
RewriteCond %{HTTP_HOST} ^(www\.)?domain2\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/domain2/web
RewriteRule ^(.*)$ /domain2/web$1 [L]
now when I type in domain1 in the adress bar. The project works correctly. What I get in the adress bar is: "domain1.com/domain1/web" And I'd like to get rid of the domain1/web part so that the functionality stays. Do I somehow use rewrite base? Or is there an other way for me to get my result? please help. Note that I'm not really used to working with .htaccess so please be gentle :)

Resources