Codeigniter url/links with mode rewrite htacess: object not found - .htaccess

I am working on project using codeigniter for the first time with bootstrap 3.
My application and system folder from CI is located outside my 'project.main' folder. Everything works fine until I try to use .htaccess in my project.
I am using an XAMPP server and I already loaded the rewrite module and as well as the AllowOverride All and restarted my server.
My url now looks like this 'http://localhost/project.main/' ..
Now my question is since I already removed the 'index.php', my navbar links in bootstrap was like this
'<a href='<?php echo site_url("pages/view/about"); ?>
but if I click it I am directed to the url
'http://localhost/project.main/pages/view/about' which gives me
Object not found' error page.
But if I use href=' <?php echo site_url("index.php/pages/view/about"); ?> I am routed to the right page.
Which is the right way of doing it? and under my config.php I have this $config['uri_protocol'] = 'REQUEST_URI '; is it necessary that uri_protocol match what is on the .htaccess under RewriteCond %(REQUEST_URI)..?
What i read in github there are two versions of .htaccess.

You didnt mention changing index page to blank inside config.php ? In case of emergency I give you my simple htaccess. It works when moving application and system folders out of public.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Also try to switch uri_protocol option.
Here's the ultimate solution for index.php How to remove "index.php" in codeigniter's path .

Related

Mod Rewrite tweak to ignore asset directories

I'm configuring Expression Engine on Windows using IIS and have ISAPI v3 Rewrite installed.
It's partly working. The main site and subpages work but needs to be modified because some web page assets are stored in similarly named directories.
The recommended Rewrite provided by Ellislabs is this and I've modified it a little to work with our Win 2012 IIS 8 server:
RewriteEngine On
RewriteBase /
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) abc/$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ abc/index.php?/$1 [L]
For example, the URL http://oursite.example.com/abc works.
Subpages are mostly working and I suspect this applies to any page really but I'm noticing it on subpages. It removes index.php and mostly loads, such as http://oursite.example.com/abc/subdept/page/
However our developer has some assets kept in a server directory named /uploads/abc/ so if a page refers to this directory, it fails to load those assets because it contains the same name, "abc".
Thus, what is the best way to handle this?
I'm guessing I can either tell it to ignore "uploads/cls" or correct the current Rewrite so that it only looks at the first "abc". I'd like for the solution to cover most similar issues that would arise so I don't have to keep modifying it. We have 12 sites and I'll have to apply the solution to each one.
Everything I've tried hasn't worked.
Also, I thought !-f and !-d would tell it to ignore it if the file or directory existed and that doesn't seem to be working as I'd expect here because these images in /uploads/abc/ do exists.
Thanks!
--
Additionally just trying to get it to work at all, I tried adding a htaccess file with "RewriteEngine Off" in the /uploads/abc/ directory and that failed to fix it.
I also tried to add this after each comment and it fails to fix it:
RewriteCond %{REQUEST_URI} !^/excluded-folder/.*$
Seeing how both of the above attempts fail to fix it, I'm wondering if there could be something else going on. Any ideas?
My rewrite was fine. The problem turned out to be code within an Expression Engine template that the in house developer created. They updated the code and the images are loading fine now.

htaccess rule to consider double slashes as single

I am working on a project built using codeigniter. And the mistake I have made is that I have added "/" after the base_url() method in many links(href) I have given on the project files as shown below.
<? echo base_url();?>/about
So the URLS are looking like
http://myproject.com//about
in place of
http://myproject.com/about
And because of that, it is resulting to 404 error.
Now the situation is that the site is ready but I am only allowed to update the .htaccess file of the project to fix this.
So is there any rule I can write in .htaccess file so that it considers the double slashes in the URL as single slash and open the specific page?
Funny thing is, it was already considering double slashes as single slash somehow and opening the "About" page on the development server. But now as the server is changed, I have started facing the 404 issues.
You can use this rule as very first rule in your DOCUMENT_ROOT/.htaccess file to remove multiple //:
RewriteEngine On
RewriteCond %{THE_REQUEST} //
RewriteRule ^(.+?)/?$ /$1 [R=302,L,NE]
actually you have set the base url as
$config['base_url'] = 'http://myproject.com/';
and when u are using it like this
<? echo base_url();?>/about
it is adding to // so you have to change your page like this
<? echo base_url();?>about
and if you cant change your path then you can set your htaccess as
RewriteEngine On
RewriteCond %{THE_REQUEST} //
RewriteRule ^(.+?)/?$ /$1 [R=302,L,NE]

WordPress plugin links not working

I'm developing a plugin with the latest version of WordPress (3.4.2) locally (XAMPP 1.7.7 [PHP: 5.3.8]) and for some reason the links are not working within the plugin. I just have a simple delete link that links to a 'delete-gallery.php' file from within the plugin admin page. This file (delete-gallery.php) only calls a function to delete the record from the database and redirects back to the page that called it (the plugin admin page). Simple enough. But, when the link is clicked I get directed to XAMPP root (localhost:8080/xampp) and not the requested destination (delete-gallery.php) for some reason.
$url = plugins_url('includes/delete-gallery.php', _FILE_);
echo 'Delete';
I know the hrefs' path is correct on the link because it shows up in the status bar on hover, but for some reason it's not locating the file locally on submission. If I set the destination to somewhere external (ie. google.com, etc) it works fine, but not locally within wordpress.
The permalink structure has been updated and the .htaccess file is currently as so:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
If I use a blank .htaccess file I don't get redirected to the XAMPP root, but instead get the error 'Object not found! The requested URL was not found on this server. ...' when the link is clicked.
Is there something that needs to be set in .htaccess to allow redirecting locally within wordpress? I'm at a loss here. Any suggestions would be greatly appreciated.
It was a simple sytax error. Had single underscores instead of doubles in the FILE parameter.
_FILE_ -> __FILE__

url re writing in .htaccess in codeigniter app

I have a codeigniter app and i wanted to remove index.php from the URI. so from the codeigniter wiki i used this script.
It stopped working once i change a config, after this change all my urls only returned home page. No matter what link i used, it only gives me the home page of my site. So i reverted it back to index.php but the server still works the same way. I tried deleting the .htacess file completely then update it with the new one which actually works but even then its working the same way. (all urls redirected to home page) Im totally out of clue, on whats wrong with my script or server.
P.S : when using .htacess i did make $config["index"] to be blank.
UPDATE
Now i removed everything else from my .htaccess file and i have only this which is the essential part to remove index.php from uri segment
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Even with only these all my urls are taking me only to the home page. I am clueless as of whats happening.
In your app/config/config.php try changing the value of:
$config['uri_protocol'] = 'AUTO';
to:
$config['uri_protocol'] = 'REQUEST_URI';
If still not working, try the remaining options (PATH_INFO, QUERY_STRING, ORIG_PATH_INFO).
Your ErrorDocument line is inside <IfModule !mod_rewrite.c> which to me looks like you don't have the mod_rewrite module installed. (If you did, that line would be ignored.) The ErrorDocument 404 /index.php line is a hack to get you to the /index.php file in case a request comes in for a file that doesn't exist.
To set the 404 page in CodeIgnitor, you need to edit your routes.php file.
$route['404_override'] = 'general/not_found';
More details.

Cannot remove index.php from my urls in Codeigniter

I am using codeigniter and when I set up the website I added necessary code in my .htaccess file to remove index.php (default) from my urls. I just happened to replace my public_html folder from a back up file of my website. Since I did that, I cannot get any of the links on home page to work unless insert index.php in the url between the domain name and the rest of the url as in http://www.obsia.com/index.php/contact/ instead of http://www.obsia.com/contact/ and it works. So, in my config file within the application folder, I changed
$config['index_page'] = "";
to
$config['index_page'] = "index.php";
and all the links seem to work now. But how do I remove index.php from the URLs.
Here is what my .htaccess code looks like:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|public|user_guide|robots\.txt|css)
RewriteRule ^(.*)$ /index.php?/$1 [L]
Can anyone point me in the right direction. It will much appreciated.
Regards,
G
What yo want to do can be done this way:
RewriteEngine on
RewriteBase /
# Static content. Rewrite to - (don't change) and mark as last rule.
RewriteRule !^(index\.php|public|user_guide|robots\.txt|css) - [L]
# Do the rewrite.
RewriteRule ^(.*)$ /index.php?/$1 [L]
However, a slightly better way of doing that is this:
RewriteEngine on
RewriteBase /
# Only do the rewrite under the condition that the requested URL isn't a (real) file.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?/$1 [L]
there are so many ht access files... In my case i was editing the wrong file... u should edit the file that is inside the project.. for example i work on code igniter and project name was test , so inside test folder i had a htaccess file and inside my application folder ie test/application there was another htaccess file.. i was editing the access file inside the application folder, but i had to edit the file in test folder not test/application/.htaccess.... hope sum 1 finds this useful.. cos i spent half a day to figure this out :(
Cheers
ksp

Resources