Codeigniter within directory htaccess - .htaccess

I have a codeigniter project light inside the folder projects, it looks like this site.com/projects/light. For some reason the standard .htaccess will not route all calls to index.php. What needs to be changed or added?
RewriteEngine on
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

It looks like the RewriteRule is redirecting to /index.php, rather than /projects/light/index.php.

Related

htaccess rewrite old php files to CodeIgniter file

I'm trying to redirect old site files toward new CodeIgniter site with .htaccess.
So, my old file
www.mysite.com/news/new?id=123
have to redirect to
www.mysite.com/news/new/123
For now, my .htaccess has inside usually code to remove index.php and it works fine.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*)$ index.php?/$1
But when I try the old file redirect nothing works.
I think the issue's about CodeIgniter, becouse if I make a simple redirect to an external file, like phpinfo.php it works fine, but if a try the redirect to index.php (of CodeIgniter) it doesn't load index.php but try to load other. Also does if I delete .htaccess code for index.php (see upside).
So,
RewriteRule news/new.php phpinfo.php [L] # it works
but
RewriteRule news/new.php index.php [L] # it doesn't work
Codeigniter use REQUEST_URI Apache variable that can not change with RewriteRule and without redirection. So you can use _remap function in news controller to call your custom method.
Other way that can be doing with htaccess is enabling query string.
Try
RewriteRule news/new\?id=(.*)$ index.php/news/new/$1 [L]

Hiding index.php from ALL subdirectories using .htaccess

So I'm building an ecommerce website using a file structure suggested to me, it looks like this:
http://www.sample.com/index.php
http://www.sample.com/department/index.php
http://www.sample.com/department/men/index.php
Basically I want to get rid of all the index.php filenames in the url, so it looks like this:
http://www.sample.com
http://www.sample.com/department
http://www.sample.com/department/men
I've achieved this for my homepage with adding this code in .htaccess:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
But, is there any way to apply this rule to every subdirectory in my site with just editing the root .htaccess file? I'm guessing it can be done by adding this rule in .htaccess files in every directory but I'd rather just have one.
Also, is this even a good way to structure a website? I am not particularly fond of it as there are so many index.php files but I'm not sure of a better alternative...
Try putting these rules above the rules that you have in your htaccess file in the document root:
RewriteRule ^index.php$ / [L,R=301]
RewriteRule ^(.+)/index.php$ /$1/ [L,R=301]

modrewrite - rewrite to new domain from subdirectory

Damn you modrewrite
I have a website hosted at a url like:
http://mydomain/mocks/thesite/
Now I want to move it to a new domain
http://thesitesdomain.com/
My htaccess looks like this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule (.*) http://www.thesitesdomain.com/$1 [R=301,L]
Now this works fine as long as there is something after /mocks/thesite/. eg: http://mydomain/mocks/thesite/index.html redirects to http://www.thesitesdomain.com/index.php.
However the problem is that:
http://mydomain/mocks/thesite/ redirects to http://thesitesdomain.com/mocks/thesite/. Any idea why? How to stop this?
The .htaccess file is in the root of /mocks/thesite/ (if that helps)
Thank you
You should try to use the variable REQUEST_URI you might have a little more success with that. It should be the request uri and file name. To
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI} [R=301,L]
I can't remember but to also redirect with the query string (get variables) I think you need to add it like this.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.thesitesdomain\.com
RewriteRule .* http://www.thesitesdomain.com/%{REQUEST_URI}?%{QUERY_STRING} [R=301,L]
Been a while since really doing a domain redirect....
BTW this is a good read on htacces configuration:
http://corz.org/serv/tricks/htaccess2.php

How to ignore .htaccess file from a parent directory?

I'm using rewrite rules for nice URL's on my websites, the problem is, that I'm supposed to upload a new website and keep an already existing e-shop running. The e-shop is in it's own folder called "shop" in the "/www" directory on the server.
But now my .htaccess file is messing with the e-shop, although it's in the parent directory, how should I block it's effects in the "/shop" dir?
Here's the code:
RewriteRule ^shop/?$ shop/ [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3&detail4=$4 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2&detail3=$3 [QSA,L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?detail1=$1&detail2=$2 [QSA,L]
RewriteRule ^([^/\.]+)/?$ index.php?detail1=$1 [QSA,L]
Thanks for any help, Mike.
Try adding this above all of your rules:
RewriteCond %{REQUEST_URI} !^/shop
Then add a .htaccess file to the /shop directory with just this in it.
RewriteOptions Inherit

CakePHP folders in webroot get redirected to app/webroot/folder

In CakePHP you can access files in webroot via domain/file
For example the favicon.ico file located at app/webroot/favicon.ico can be accessed from
example.com/favicon.ico
Directories on the other hand seem to have a gotcha.
If I have a directory called blog in the app/webroot/, then as long as I try to access it like:
example.com/blog/
Then it works as expected. However if I try to access it without the trailing slash:
example.com/blog
Then it gets redirected to:
example.com/app/webroot/blog/
This is undesired. I woult rather .com/folder get redirected to .com/folder/ instead of .com/app/webroot/folder/
Is there a way to set this up?
If you installed wordpress blog and cakephp in document root, you need to replace .htaccess file script with below script:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/YOUR_WORDPRESS_DIR.*
RewriteCond %{REQUEST_URI} !-f
RewriteRule ^$ app/webroot/ [L]
RewriteCond %{REQUEST_URI} !^/YOUR_WORDPRESS_DIR.*
RewriteCond %{REQUEST_URI} !-d
RewriteRule (.*) app/webroot/$1 [L]
What about using the Router::Connect for blog to redirect directly to the good page? Of course this is not an automatic routine but it mighthelp you.
More info : http://book.cakephp.org/view/945/Routes-Configuration
I suppose there might be a parameter in the config core files, have you already had a look there?
You could try the instructions here

Resources