htaccess issue in codeigniter - apache

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]

Related

Apache configured to ridirect urls to Joomla but then How can I still access Moodle?

I configured the .htaccess file like this:
Mod_rewrite in use.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/pathtopublichtml/joomla/
RewriteRule ^(.*)$ /pathtopublichtml/joomla/$1 [L]
But then when I try to get to /domain.com/moodle Apache takes me to Joomla. How Can I access both ?
You can add another RewriteCond to exclude any REQUEST_URI that starts with 'moodle'
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?domain.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/pathtopublichtml/joomla/
# Make sure the redirect is not done for moodle
RewriteCond %{REQUEST_URI} !^moodle
RewriteRule ^(.*)$ /pathtopublichtml/joomla/$1 [L]

.htaccess conflictions on different directories

Probably a duplicate question but here goes!
I'm not great at htaccess stuff. I've been using codeigniter and have multiple projects going on currently. I've made a redirect in my public_html to redirect to a directory called "home" right? And in this direct is the base for a codeigniter application where I have another .htaccess file removing the index.php from the url for controllers etc.
My question is are these two files conflicting one another? Here's my code:
public_html/.htaccess
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^myurl.co.uk$
RewriteRule (.*) http://www.myurl/home/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www.myurl.co.uk$
RewriteRule (.*) http://www.myurl/home/$1 [R=301,L]
/home/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
Also another question would be could I display my /home/index.php file on landing on myurl.co.uk without having home in the url?
In my public_html directory htaccess files I have
RewriteEngine on
RewriteCond %{HTTP_HOST} ^myurl.co.uk$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.myurl.co.uk$
RewriteCond %{REQUEST_URI} !home/
RewriteRule (.*) /home/index.php/$1 [L]
And I changed my base url to http://www.myurl.co.uk/ whereas before I had http://www.myurl.co.uk/home. Ma bad!

Redirect site in .htaccess

We have our LMS hosted on shared hosting server.
Our main domain is exampletraining.com
Our public_html folder has following folders inside it:
cgi-bin
lms
moodle
.htaccess
We added following lines to .htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^exampletraining.com/$ [NC,OR]
RewriteCond %{HTTP_HOST} ^exampletraining.com$
RewriteCond %{REQUEST_URI} !lms/
RewriteRule (.*) /lms/$1 [L]
so that exampletraining.com should always show the content of exampletraining.com/lms
But our problem is that now we are unable to access exampletraining.com/moodle
What should we change in our .htaccess file so that we can also access exampletraining.com/moodle?
Thanks.
Just add an exception for moodle:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^exampletraining\.com$ [NC]
RewriteCond %{REQUEST_URI} !/(lms|moodle)/ [NC]
RewriteRule (.*) lms/$1 [L]
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteCond %{REQUEST_URI} !^/subfolder/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$ [NC]
RewriteRule ^(/)?$ subfolder/index.php [L]
---
Within an htaccess file, the scope of the <Files> directive only applies to that directory (I guess to avoid confusion when rules/directives in the htaccess of subdirectories get applied superceding ones from the parent).
So you can have:
<Files "log.txt">
Order Allow,Deny
Deny from all
</Files>
In an htaccess file in your inscription directory. Or you can use mod_rewrite to sort of handle both cases deny access to htaccess file as well as log.txt:
RewriteRule /?.htaccess$ - [F,L]
RewriteRule ^/?inscription/log.txt$ - [F,L]

htaccess - canonical URL when redirecting to subdirectory

I've been playing around with this problem for quite a while but can't find the way how to achieve what I want. I want user coming to my website test.com to reach index.php located in subdirectory www immediatelly, which I am able to do. But when the URL is test.com/www I want it to be just test.com.
Snippets of code:
.htaccess in /
RewriteRule ^(.*)$ /www/$1 [L]
.htaccess in /www
RewriteCond %{REQUEST_URI} ^/www.*$
RewriteRule ^/www/(.*)$ /$1 [L]
gives me 500 Internal Error.
UPDATE:
I came to a solution thanks to #Justin Iurman's answer:
.htaccess in /www
RewriteCond %{THE_REQUEST} \ /www/?(.*)\ HTTP/ [NC]
RewriteRule ^(.*)$ /%1 [R=301,L]
Have another problem tho. On the server machine I have multiple websites and I want to serve files according to HTTP_HOST variable in root .htaccess file. I redirect user accessing test.com to proper directory (say test), but I want URL test.com/test to redirect just to test.com. Directory test contains directory www where user is redirected and it does not stick to URL thanks to solution above. I would like to edit just .htaccess file in webserver root so I don't have any dependancy on websites' domains in projects.
SOLVED
.htaccess in webserver root:
<IfModule mod_rewrite.c>
RewriteEngine On
# Redirect test.com/test (and everything into test folder) to test.com root
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteCond %{THE_REQUEST} \ /test/? [NC]
RewriteRule ^.*$ / [R=301,L]
# Forward (internally rewrite) test.com/one/example/page to test.com/test/www/one/example/page
RewriteCond %{HTTP_HOST} ^test\.com$ [NC]
RewriteRule ^(.*)$ /test/www/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
.htaccess in the "test" directory:
<IfModule mod_rewrite.c>
RewriteEngine On
# allow /test in URL only for certain filetypes
RewriteRule ^(.*\.(pdf|js|ico|gif|jpg|png|css|rar|zip|tar\.gz))$ /test/www/$1 [L]
# allow /test on localhost
RewriteCond %{HTTP_HOST} ^localhost$ [NC]
RewriteRule ^(.*)$ /test/www/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
Thanks a lot Justin!
You have to avoid infinite loop when doing what you want.
Put this code in your htaccess
RewriteEngine on
RewriteCond %{THE_REQUEST} \ /www/?(.*)\ HTTP/ [NC]
RewriteRule . /%1 [R=301,L]
RewriteRule ^(.*)$ /www/$1 [L]
EDIT: taking your update into consideration, here's the new code
RewriteEngine on
# Redirect test.com/test (and everything into test folder) to test.com root
RewriteCond %{HTTP_HOST} ^test.com$ [NC]
RewriteCond %{THE_REQUEST} \ /test/? [NC]
RewriteRule . / [R=301,L]
# Forward (internally rewrite) test.com/one/example/page to test.com/test/www/one/example/page
RewriteCond %{HTTP_HOST} ^test.com$ [NC]
RewriteRule ^(.*)$ /test/www/$1 [L]

htaccess - subfolder serve as root domain

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