Problem with removing Index.php from URL |
Hi Guys
I'm having a problem removing the index.php part in my website's url. I'm currently migrating a webapplication from 1.7.2 to the new 3.0.4 Version. The Code was a bit outdated and it took quite some time to rewrite some classes and getting it functionning again. But now there is only one last Problem that needs to be solved: Removing Index.php from my URL. To understand what is not working here a little summary of the Webapplication: The Application shows all authorized users our companys serversystems. On the left side, one can choose to filter for OS-Versions or Operating Status or even search for specific servernames or IPs. On the right Side is a List, that updates in realtime and shows the matching Systems. If a user clicks on a serversystem in the right list, general Information about the serversystem will be dispalyed in the middle of the Site. The problem now is, when I change the Option in application/config/config.php from $config['index_page'] = 'index.php'; to $config['index_page'] = ''; my whole site stops working. Either the search nor the filter function are working anymore. The links altough are correct, hiding the index.php page from the url like: https://www.example.ch/system/showItem/123456 which means that my mod_rewrite in the /.htaccess is working correctly (I think so). I also changed the uri_protocol option to REQUEST_URI. I hope you guys understand my problem and also my english. I would be glad if someone has a guess that could bring me to a solution. Thanks in advance Fuerro
Try this .htaccess file, also you should upgrade to CI v3.0.6
Code: <IfModule mod_rewrite.c> What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
<IfModule mod_rewrite.c>
RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule . index.php/$1 [QSA,L] </IfModule> if your site in a subfolder, write the folder name in RewriteBase section. for example if your site is in a folder you must be write the name of folder between // : RewriteBase /foldername/
I did the Update and also am using your .htaccess-file now.
It remains unchanged. Thank you anyway!
06-17-2016, 12:47 PM
(This post was last modified: 06-17-2016, 12:55 PM by behrooz1x. Edit Reason: complete )
You needs three steps:
1-Create htaccess file in the root ci folder(i attach my .htaccess). 2-Change the 'RewriteBase /' in httaccess, for exmaple if your site in url is 'http://localhost/ci/index.php/welcome' you need change that to 'RewriteBase /ci/'. 3-remove 'index.php' from 'application/config/config.php': //this $config['index_page'] = 'index.php'; ///to $config['index_page'] = '';
Thank you for your suggestions.
I tried it now with different RewriteBase variants but it doesn't seem to change a thing. What is unclear for me is, when I remove index.php out of my config.php what happens with all the configurations made in the file? like: $system_path = 'system'; or $application_folder = 'application'; ? Isn't this equal to deleting this file? CI doesn't use it anymore?
No, it is just a config setting and nothing is deleted.
The .htaccess file simply takes the incoming request and reroutes it to the same url, but inserting index.php back into the route, so index.php is still run of course. Imagine renaming index.php to myfile.php, then the config setting would be 'myfile.php' and CI would know what to write into the urls. If you remove it from the config setting, then the htaccess file would be changed to insert myfile.php into the url route as the request came in. So myfile.php would still be run. I hope that helps, Paul. PS If you remove index.php from config, but do not rewrite the url with htaccess, the url's created will be wrong, and CI will not run because index.php was never called. PPS To check your .htaccess is even being read, force it to make an error by putting junk in the first line like 'fghdfkghdslkfgh'. If you get a server error, then it is being read. Next make a test.html file to say 'hello world' and try rewriting the url to the test.html. You can then check your .htaccess is read and working. Googling for test my .htaccess gives some good help on this
So it seems that my .htaccess file isn't used by apache.
I know that mod_rewrite is working, because I already tested it once. But I was not thinking about the fact that my file isn't even read by Apache. That may be the solution, I'm working on it. Thanks!
Glad you have a clue to work on at least. There is nothing more frustrating than when you just can't even find what to investigate.
Just to note, are you changing the correct htaccess file. The one to do the rewriting URL's in should be in the root of your CI application, not the .htaccess files in the app folders or other CI folders.
I solved it! First problem was, that I've had "AllowOverride None" active in my Directory.. And then one of my controllers was named "system" like Ci's System-folder which leaded to another problem. Renamed it and now everything is working perfectly and I'm just sitting here after hours of cheking my code facepalming myself.
Thanks alot, would still be checking my code without you guys' help! Awesome! |
Welcome Guest, Not a member yet? Register Sign In |