Welcome Guest, Not a member yet? Register   Sign In
Problem with HTACCESS, URL and link Javascript
#1

[eluser]bobcute[/eluser]
Hi,

I'm getting frustrated with this problem:

1. I've set the htaccess with this code to remove the index.php in the url:

.htaccess

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

2. I've set the index page to blank in order for the htaccess to function. (I cannot understand why?)

config.php

Code:
$config['index_page'] = ""; //

3. Ive added the this code in the route.php to link the page in the default controller in order to have a lesser url (ex. www.example.com/requestedpage)

Code:
$route['(:any)'] = 'content/$1';

Now these are the problem:

a. I cannot open my base_url unless you added the /index.php. It will add the following error on the heading of the page:

A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 0
Filename: libraries/Router.php
Line Number: 201

b. I cannot open/link the javascript file like www.example.com/AC_RunActiveContent.js, it will display "404 page not found".


Please help! Since I started codeigniter, this problem always exist since I cannot find the any solution.

Thanks.
#2

[eluser]Phil Sturgeon[/eluser]
1.) Instead of your current RewriteCond, use this:

Quote:RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

This will make your .htaccess file look like this (I expect)

Quote:RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

This basically means, instead of sending everything other than index.php, /images/ and robots.txt through CodeIgniter, it will only send URL's that are not real files or directories. This should be standard in any .htaccess example.

2.) You are removing the index_page value as you do not want one. This is because the index_page can be renamed to something.php or index2.php, whatever you like. That would make URL's such as http://example.com/something.php/controller/method.

As we do not want anything before controller/method, we use an empty string.

3.) a. Do you have your default_controller set up properly within the application/config/routes.php file? This error will only happen if there is nothing in the URL for it to use as a segment.

b. This will be fixed by 1.).
#3

[eluser]bobcute[/eluser]
:lol: this is perfect man... your the man!..It solves everything now... It just all .htaccess! I hope in your user_guide updates we should include the following since all our files are link through base_url().

Code:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

8-/ or maybe there a reason why the user_guide used

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

instead.

Anyway thank you so much!
#4

[eluser]Phil Sturgeon[/eluser]
Well as with anything dynamic there is a slight performance overhead.

Each request it has to make a check to see if it is a real file or a real directory which are performed as two separate checks on the file system. That is obviously slower than just checking against a regular expression.

That is probably why the other method is suggested but personally I don't see enough of a difference to give a damn!




Theme © iAndrew 2016 - Forum software by © MyBB