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.
Related
I am new to AngularJS and PHP. In the application i am working on, I have enabled html5mode in angularjs using following things:-
-- Added base href in /myapp/index.html
<base href="http://localhost/myapp/" />
-- Added following at the end of config function.
$locationProvider.html5Mode(true);
When I access my application using following url: http://localhost/myapp ,
It does not append any # in browser url. I can navigate to any other route successfully. Route url is http://localhost/myapp/category/1
But when I refresh the page, above url gives me 404 error. I understood that, server trying to find file at location /myapp/category/1. I read at other places writing .htaccess rule will solve this problem. I tried all those options. Nothing worked for me.
I am using xampp and location of .htaccess file is /htdocs/myapp/.htaccess
.htaccess file is accessible, because if I add any junk data in it, url throw error.
Please help me on this. I need server to return url as it is so that angularjs can route pages correctly. Please help me to write .htaccess rule. mod_rewrite is already enabled in httpd.conf file of apache.
I can able to find solution for this. My .htaccess file will look like below
Options +FollowSymLinks
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index.html
RewriteCond %{REQUEST_URI} !.*\.(map|cssĀ¦js|html|png)
RewriteRule (.*) index.html [L]
</ifModule>
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 .
Here is my htaccess file and it works somewhat. Not matter what controller I specify it always goes to the home page
<IfModule mod_rewrite.c>
RewriteEngine On
#Checks to see if the user is attempting to access a valid file,
#such as an image or css document, if this isn't true it sends the
#request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|css|js)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
This is my website URL
http://automationmetrics.local/automation/
Thoughts?
Some things I usually check when this happens to me:
Have I enabled the mod_rewrite module in Apache?
Have I set $config['index_page'] to blank?
If the above works, here's the one that I use, that's working on my end:
https://gist.github.com/petrepatrasc/6925413
If you're STILL out of luck, then try fiddling with the $config['uri_protocol'] parameter - I remember that I could only get it to work on Windows (with IIS at the time) using REQUEST_URI as a value. Might be related to that.
The first two rules get triggered on all the files, just like it says in the comment. So this one:
RewriteCond $1 !^(index\.php|css|js)
seems redundant and removing it should solve the issue you're having.
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__
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