.htaccess linking to root - php

I am using FTP to upload a codeigniter website to a server. I have arranged the files in FTP as following (I don't have 10 in reputition):
The index.php finds the system and application folder. But I don't know what to do with the .htaccess file. I have tried various examples from the web and here's an example:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteCond %{REQUEST_URI} !^/public_html/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /public_html/$1
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
RewriteRule ^(/)?$ public_html/index.php [L]
This is the first time I use codeigniter and this question is probably stupid (sorry). I'm really thankful for all the help I can get.
I have another .htaccess file now which removes index.php from url:
RewriteEngine On
RewriteBase /example.com/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

If you want to remove index.php from urls then please use following code in .htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Copied from revision 3 of the question
So the problem wasn't the .htaccess! I fixed it by making my
controllers first letter a capital letter.

Related

How to write a simple .htaccess with two entry points

I have problem while trying to use below .htaccess file to direct my requests. every one begin with rest to rest.php and others to index.php. the problem is all request directed to index.php even the ones begin with rest. did i miss something ?
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^rest(.+)$ rest.php? [QSA,L]
RewriteRule ^(.+)$ index.php? [QSA]
below .htaccess seems to solve my problem, please if there is a bug, write it in comment.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^rest$ rest.php? [QSA,L]
RewriteRule ^rest(.+)$ rest.php? [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php? [QSA]

Not Able to remove "Index.php" from URL in codeigniter

I am new in codeigniter and i am trying to remove index.php from URL in Codeigniter but not able to do this.
I wrote code in my .htaccess file-
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
My Apache mod_rewrite is enable.
But still got 404 error when i am trying to access any controller without using index.php.
Please help.
Thanks.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
</IfModule>
Is the code I'm using, it works on every hosting platform I've used it on.
This should help you,
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
check this code of htaccess file.
DirectoryIndex index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|public|images|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
you can find your answer refference here
My .htaccess file is not working
moreover can you share your base url with us? as this error may be due to wrong baseurl set.

apache htaccess codeigniter query string to path

i'm trying to make a codeigniter based website be able to convert index.php?option=test&controller=con1 to /test/con1 using .htaccess i tried multiple examples i found and none seem to work, it goes straight to the home page. any ideas?
i've tried things like
RewriteCond %{QUERY_STRING} ^(\w+)=(\w+)$
RewriteRule ^\/(.+?)\/(.+?)\/? /index.php/$1/$2 [L]
but doesn't throw any errors or anything.
my current htacces is
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|img|js|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
try put this .htaccess in same directory with your index.php
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Htaccess conflicts

I am trying to do some rewrites with my .htaccess file
All I am trying to do is rewrite the url:
www.example.com/book.php?course=#WHATEVERSLUG
to
www.example.com/course/#WHATEVERSLUG
WHICH I HAVE SUCCESSFULLY BEEN USING THE CODE BELOW FOR A WHILE NOW WITH NO ERRORS
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^course\/([^/\.]+)/?$ book.php?course=$1 [L]
Then, I tried adding another rewrite mod, below:
RewriteRule ^(.*)\/(\?.*)?$ $1$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]
to shorten my urls by removing the .php extensions, and remove the traling slashes and it appears that they do not mix well for some reason. I am not very good with .Htaccess, so any help will be possitive.
Or if someone has another suggestion to rewrite:
www.example.com/book.php?course=#WHATEVERSLUG
to
www.example.com/course/#WHATEVERSLUG
And
Rewrite .php files to remove extenstions and traling slashes..
it'd be so greately appreciated. Thank you in advance.
Figured it out!:
w/ a little a help from: Multiple conflicting htaccess RewriteRules
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^course\/([^/\.]+)/?$ ./book.php?course=$1

CodeIgniter Routing

I'm trying to build a short URI service with CI just so I can learn CI faster
anyway .. I got stuck at the routing
i hid the index.php then added the following route $route['([A-z0-9]{4})'] = "/forward/redirect/$1";
but it just shows my default controller
I also tried with HTaccess
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ /forward/redirect/$1 [NC]
It gives an error for not having any passed data
any help is appreciated.
Cheers
Since there is no physical path /forward/redirect/, you should redirect to the "catch all" index.php file in the root and input the path as parameter:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ /index.php/forward/redirect/$1 [NC]
Or you can leave the rule as is and append another rule (this way you will have two rewriting cycles, the first one will rewrite to /forward/redirect/asdf and then the second one rewrites to index.php/forward/redirect/asdf:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ /forward/redirect/$1 [NC]
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
i finally got it working >_>
routes file contains this
$route['([A-z0-9]{4})'] = "/forward/redirect/$1";
htaccess contains this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*) http://%1/$1 [R=301]
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([A-z0-9]{4})$ index.php/forward/redirect/?$1 [NC]
RewriteCond $1 !^(index\.php|images|robots\.txt|(.*).js|(.*).css|(.*).jpg|(.*).png)
//added (.*) so resources could be loaded properly :)
RewriteRule ^(.*)$ /index.php/$1 [L]

Categories