0

I am using the htaccess provided by codeigniter in their website. Everything works file, but when i use a / after the url, everything gets messed up. say my domain is www.example.com/mycontroller this will work fine but www.example.com/mycontroller/ makes every thing messed up, no style no image and all that.

I solved the issue by using base_url() in front of the links for stylesheet and images etc. But isnt there any other way so that I dont have to go through every image and link to add base_url().

The .htaccess file contains

RewriteEngine on
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
1
  • base_url sounds like the best way to do it. It's modifiable and extensible. Commented Feb 12, 2013 at 18:57

2 Answers 2

2

You should allow files and folders to pass

RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]

And yes, you should add base_url, otherwise your application is less portable and maintenance becomes a nightmare

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

Comments

1

Try to check if the request points to a file or a directory:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php|css|images|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]

If you don't have some realy good reasons you can link relative to the base directory for images or css files.

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.