Codeigniter controller/views 'pretty uri' not working - codeigniter

I'm a complete Codeigniter noob.
I think I have everything setup properly, and the pages display when I go to:
http://www.example.com/index.php/pages/view/my_page
but I get an Apache 404 error when I visit without the index.php file:
http://www.example.com/pages/view/my_page
Is there anything obvious I'm missing? .htaccess rules, or a change in the controller?

By default, the index.php file will be included in your URL
You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

Related

codeigniter page not found on live server

codeigniter page not found showing but working fine in local server.
I had uploaded codeigniter file of one basic simple page on live server but there it is showing no page found and same file it is working on local server.
In that I had
mine.php ---- controller
index.php --- view
I loaded in routes default controller - mine in config base url- domain.com removed index.php also
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
can I know please why it is showing page not found, might be some routing issue but I had loaded default controller also. Please help out on this
First of all start error logging properly so you can see the actuall error.
Change your file name's first letter capital. This is mendetory as explained here ci3 manual - controllers. It says class name as well as file name must start with capital. ( If your Dev machine is windows then it will not show errors if you don't follow this rule. Because window's file system is case insensitive. But on your server it is linux.so it will show error)
If you still don't get it working then try access the url with index.php in it. Temporaryly disable .htaccess .If you get it working then may be you have problem in . htaccess. Try the following link to properly remove index.php from your url. Expression engine forum .This htaccess worked for me on all different server I have used.
add this in .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|images|asset|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

How to mod-rewrite the url with custom extension

I need to change the pattern of my url from the normal path into a subdomain. I tried write the .htaccess but it's not work.
http://hello.com/sos/article.php?id=1&title=this-is-a-title.php
From the url above I want to:
Change the pattern to call the page so I remove sos before the domain as a subdomain. So I'd got http://sos.hello.com/
I need the variable to be replaced with forward slash and suffixed with .sos. As the story is about warning : article/1/this-is-a-title.sos
I wish I could have something like this:
http://sos.hello.com/article/1/this-is-a-title.sos
So I wrote :
RewriteEngine On
RewriteRule ^article/([^/]*)/([^/]*)\.sos$ /article.php?id=$1&title=$2 [L]
And guess what! It's not work. Please point me out. What I've done wrong???
I've got the answer after several tries:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.hello.com
RedirectMatch 301 ^/sos/$ http://sos.hello.com/mypage.php
RewriteRule ^article/([^/]*)/([^/]*)\.sos$ /article.php?id=$1&title=$2 [L]
save as .htaccess to the subdomain directory

Magento, redirect the url from "www.domain.com/home" to base url "www.domain.com"

I am trying to configure how to redirect my magento website from www.domain.com/home to base url www.domain.com, it always redirecting to www.domain.com/home
UPDATE
Thanks Amit, I use your solution
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/accueil
RewriteRule ^(.*)accueil$ http://www.cabas-durables.fr/$1 [R=301,L]
but I got error at the browser says
The page isn't redirecting properly
then I change the $1 after http://www.cabas-durables.fr/$1 to index.php, then it shows "http://www.cabas-durables.fr/index.php" at the browser, then I bring it back to $1 I got no error but it stays to "http://www.cabas-durables.fr/index.php"
I don't know where to change it to only "http://www.cabas-durables.fr/"
I will have problem with SEO if it not change
thanks
It can be better to use htaccess.
find
Options +FollowSymLinks
RewriteEngine on
Then
Put the below code in htaccess file
RewriteCond %{THE_REQUEST} ^.*/home
RewriteRule ^(.*)home$ http://www.domain.com/$1 [R=301,L]
Create URL Redirect in admin panel.
Use tagret path - "../"; it will redirect to the homepage.

How to remove index.php from a URL from CodeIgniter?

I am new to CodeIgniter. I have an XAMPP server on Windows 8. Everything is fine, but the problem is about my URL, it doesn't look friendly. It looks like localhost/ci/index.php/site/home (where ci is my root folder for CodeIgniter). I want to make the URL more clean, like localhost/ci/home, how can I do it?
My CodeIgniter version is 2.1.2.
I have done some research already, but in most of the cases it says to change the .htaccess file of CodeIgniter. But I have nothing in the .htaccess file; it's empty, except the line "Deny from all".
You can do this, in config/config.php:
$config['base_url'] = 'http://'.$_SERVER['HTTP_HOST']; //you can also leave blank this CI tend to find this by himself
$config['index_page'] = '';
And try the following .htaccess. I use it for many sites, and it satisfies me.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
If it is not working yet, use a phpinfo(); and check if mod_rewrite is enabled. If it is not enabled, you can follow the instructions in Stack Overflow question How do you enable mod_rewrite? to enable that.
If it is not working yet and mod_rewrite is enabled yet, you can try to switch these in config/config.php:
$config['uri_protocol'] = 'AUTO'; //If not working, try one of these:
'PATH_INFO' Uses the PATH_INFO
| 'QUERY_STRING' Uses the QUERY_STRING
| 'REQUEST_URI' Uses the REQUEST_URI
| 'ORIG_PATH_INFO' Uses the ORIG_PATH_INFO
You need to replace "Deny from all" with this:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
http://ellislab.com/codeigniter/user-guide/general/urls.html
Looking at the official documentation, CodeIgniter URLs:
You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:
RewriteEngine on<br>
RewriteCond $1 !^(index\.php|images|robots\.txt)<br>
RewriteRule ^(.*)$ /index.php/$1 [L]<br>
Also if you are using Apache place .htaccess file in your root web directory. For more information, look in Codeigniter .htaccess.

How can i route to a controller and function in codeigniter?

I need to route for example to "www.url.com/controller/function" i put the code in 'config.php' in routes but, doesn't work. i need to load to views in the same controller, without put 'index.php' in the url. It is possible?
By default, the index.php file will be included in your URLs:
www.url.com/index.php/controller/function
You can easily remove this file by using a .htaccess file with some simple rules. Here is an example of such a file, using the "negative" method in which everything is redirected except the specified items:
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ /index.php/$1 [L]
Put the .htaccess file containing the above code to your app root folder.
here is the helping url to remove the index.php from url
User Guide remove index.php
you have to use .htaccess file to remove index.php from url
Hope it helps
Updated
Have a look in the application\config\config.php file, there is a variable named 'index_page'
It should look like this
$config['index_page'] = "index.php";
change it to
$config['index_page'] = "";
here is the .htaccess file you can use this..
RewriteEngine on
RewriteCond $1 !^(index\.php|[Javascript / CSS / Image root Folder name(s)]|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]
Here are some use full links.. you can follow these..
remove index.php stackoverflow
remove index.php codeigniter forum
Enable mod rewrite from your server
Hope these will help you

Resources