3

I know this question is more appropriate for Server Fault but unfortunately I was banned for poor quality questions (I was down voted on 2-3 questions I asked.) So the next best place to ask these questions are here.

I have two problems related to CodeIgniter routing.

The first problem is that I can't seem to get rid of index.php in the url. I followed the instructions on how to remove it. I have the following mod rewrite code in my .htaccess file (see below) at the root of my WAMP server (CI is located at the root, not in its own folder). I have uncommented this line in httpd.conf file LoadModule rewrite_module modules/mod_rewrite.so. I deleted index.php from $config['index_page'] = "index.php";. And I restarted all WAMP services.

My second problem is that I have a controller called search and a method called index. I would like to change the resultant URL from http://localhost/index.php/search/index to http://localhost/search/whatever_im_searching_for. I tried the following custom route in my routes.php file but it did not work: $route['search/(.*)'] = "search/$1";

RewriteEngine On

# Put your installation directory here:
# If your URL is www.example.com/, use /
# If your URL is www.example.com/site_folder/, use /site_folder/

RewriteBase /

# Do not enable rewriting for files or directories that exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# For reuests that are not actual files or directories,
# Rewrite to index.php/URL
RewriteRule ^(.*)$ index.php/$1 [PT,L]

I am struggling to understand the code in .htaccess and on how to use CI's custom routing. Any assistance will be greatly appreciated. Thank you in advance.


EDIT 1

enter image description here

4 Answers 4

1

Edit your htaccess like this:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond %{REQUEST_URI} ^LoginTut.*
RewriteRule ^(.*)$ index.php?/$1 [L]

RewriteCond $1 !^(index\.php|images|table-images|js|robots\.txt|css|captcha)

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
 ErrorDocument 404 index.php
</IfModule>

To have your searchterms in the url you can look at this:

https://stackoverflow.com/a/12070284/1379394

Sign up to request clarification or add additional context in comments.

4 Comments

+1 Thank you for your reply Kees. Unfortunately, i'm still getting the index.php in my url. I pasted your code in the .htaccess file in my root and restarted all WAMP services. I find this is very strange! I've edited my question to include a screen shot of my www directory. What else can I try?
My uri_protocol in config.php is set to $config['uri_protocol'] = 'AUTO'; Does this have anything to do with my problem?
I have another .htaccess file inside the application directory that has Deny from all
uri_protocol is set to AUTO by default. So that has nothing to do with it.
1

Second problem:

$route['search/(:any)'] = "search/index/$1";

1 Comment

+1 Thank you for your reply. Unfortunately, it did not work even after I restarted WAMP services. I don't understand why none of these options are working. It used to work up to recently. I'm feel there is a setting in the httpd file that is preventing my issues from being resolved. I'm rereading httpd.apache.org/docs/2.2/howto/htaccess.html
1

Check Apache's default config file. On WAMP it's probably in

<WAMPSERVER_HOME>\bin\apache\Apache2.2.xx\conf

If it looks like this:

    DocumentRoot /var/www
    <Directory />
            Options FollowSymLinks
            AllowOverride None
    </Directory>
    <Directory /var/www/>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
    </Directory>

then change both:

AllowOverride None

to:

AllowOverride All

Comments

1

I had the same problem and I fixed only by write in my .htaccess:

RewriteEngine on

RewriteCond $1 !^(index\.php|images|robots\.txt)

RewriteRule ^(.*)$ index.php/$1 [L]

and it's working perfectly.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.