Please help with CodeIgniter assets. I tried most of the solutions from StackOverflow (including the autoload utility helper), nothing works so far. Here's my setup below:
Folder Path:
.htaccess
<IfModule mod_rewrite.cs>
RewriteBase /hnk_ci
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
When I view source code, it looks like this:
<link href="http://localhost/hnk_ci/assets/css/bootstrap.min.css" rel="stylesheet">
But when click on the css link from source code, I get this error:
The requested URL /hnk_ci/assets/css/bootstrap.min.css was not found on this server.
Related
my remote server is LiteSpeed - not Appache
not sure is it the same regarding htaccess code
original url - example.com/index.php?c=kb
.htaccess
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^home/(.*)$ /index.php?c=$1 [L]
plus - <base href="/">
result - example.com/home/kb - works fine
now I want to remove home - to get - example.com/kb
RewriteRule . /index.php [L]
the page is there but css and js are missing
seems problem is with <base href="/">
any help?
to see - example.com/kb. On server - example.com/index.php?c=kb
You may try this code for above scheme:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?c=$1 [L,QSA]
References:
Apache mod_rewrite Introduction
Apache mod_rewrite Technical Details
.htaccess tips and tricks
I have been looking for many tutorials bu no one has really helped me, I know you guys can:
My website has the following structure:
mywebsite.domain/?pg=somepage
But I would like to leave it like this:
mywebsite.domain/somepage
All the tutorials I have found work in the next structure:
mywebsite.domain/file.php?pg=somepage
So I can't gess how a RewriteRule would be using my structure.
I have tried:
RewriteEngine on
RewriteRule ^index/([0-9a-zA-Z]+) index.php/?pg=$1
And also:
RewriteEngine on
RewriteRule ^index/([0-9a-zA-Z]+) index.php?pg=$1
But I have had no luck :(
Note: My index file has .php extension
You could do something like this -
RewriteRule ^(.*)$ /index.php?pg=$1 [L]
This will redirect mywebsite.domain/somepage to mywebsite.domain/index.php?pg=somepage
or full config -
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?pg=$1 [L]
</IfModule>
for more info - Apache mod_rewrite
I am using codeigniter and I keep having these 404 errors in my log file.
ERROR - 2016-04-30 16:41:15 --> 404 Page Not Found: Assets/js
ERROR - 2016-04-30 16:41:15 --> 404 Page Not Found: Assets/js
ERROR - 2016-04-30 16:41:18 --> 404 Page Not Found: Assets/js
So every page load causes one entry of the above error in the log file. My htaccess file looks like below. What's going wrong here?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond $1 !^(index\.php|assets|myadmin|robots\.txt)
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I can confirm assets/js are valid folders.
Are you able to get to your assets folder by going through the web path? e.g. http://localhost/assets (try to retrieve a file if you dont have indexing enabled in your webserver e.g. http://localhost/assets/css/style.css), does it load?
If this is loading you are possibly calling your assets without using a base path which means a view is trying to call directly from within its own folder.
Using site_url() is a really good step (url helper)... I urge you to make your life easier in calling assets by making a simple helper and adding it to auto load containing (something like) this:
if (!function_exists('assets'))
{
/**
* Base asset directory call
*/
function assets($var)
{
$CI =& get_instance();
$CI->load->helper('url');
return site_url('assets') . '/' . $var;
}
}
You would then call it in your view:
<!-- load CSS -->
<link href="<?php echo assets("css/bootstrap.min.css") ?>" rel="stylesheet">
It would then show this once rendered:
<link href="http://localhost/assets/css/bootstrap.min.css" rel="stylesheet">
This is just a really basic example though, if you have heaps of assets to call in a header or footer, I would suggest creating a helper to load based on a config file, you can also specify what is required on certain page loads that way as well so its dynamically loaded with a foreach.
Also do be careful calling Assets (capital letter) vs assets (no capital letter) is very different, many webservers are case-sensitive...
I run the following for my htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond $1 !^(index\.php|assets|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I'm trying to 'clean up' my urls from looking like this
http://www.smokescreencreative.co.uk/index.php?pid=graphicdesign
to looking like this
http://www.smokescreencreative.co.uk/graphicdesign
I have tried using htaccess but I can't get it to work, any ideas or suggestions would be most welcome.
htaccess code that i've tried is below (the first line is what was already in the file as put there by my web host)
AddType application/x-httpd-php .php .html .htm
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^/(\w+)*$ ./index.php?pid=$1
I have also tried variations where I remove the / from after the ^, the ./ from before index, the . from before index and the * from before $ but none of these variations seem to make a difference.
Thanks for your helps guys!
Make sure your links on are in the from like this
http://www.smokescreencreative.co.uk/graphicdesign
And use this code in your .htaccess.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ /index.php?pid=$1 [L]
My site is on "localhost/mysite" but when I view it on the browser, layout and links are broken. CSS and JS files are on "localhost/mysite/themes/" but this is what I see in the source code:
<link href="/themes/new/css/style.css" rel="stylesheet"/>
<script src="/themes/new/js/scroll.js"></script>
And when I click on the links above, I always get to the following addresses and they are broken:
http://localhost/themes/new/css/style.css
http://localhost/themes/new/js/scroll.js
"mysite" path is already missing. It should be:
http://localhost/mysite/themes/new/css/style.css
http://localhost/mysite/themes/new/js/scroll.js
On htdocs\mysite\application\application\config\config.php, I have this setting and it should be left unedited.
$config['base_url'] = '';
$config['index_page'] = '';
On htdocs\mysite.htaccess, I have this setting, and it's probably the file that needs changes.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mysite/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
I looked around and tried all the suggestions by changing .htaccess but nothing really helped to make it work. It's funny when I change
href="/themes/new/css/style.css
to
href="".base_url()."themes/new/css/style.css"
everything works perfectly. But this is not the solution. It's a big site and I shouldn't be editing too much files by adding base_url() function, etc. Maybe we can do something on .htaccess? :(