Codeigniter and .htaccess file to ignore index.php - .htaccess

So I'm having a weird problem with .htaccess file and codeigniter. I have a wamp server on my local machine and there it works as expected. I have folders like that wamp/www/my_app and in my_app folder i have .htaccess file like that:
ErrorDocument 404 /index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /my_app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
And in mine config.php gile i have:
$config['base_url']='';
$config['index_page']='';
$config['uri_protocol']='AUTO';
So i tried uploading that project to debian server on link like apps.myserver.com/my_app. I put my app to folder var/www/my_app. But the trick is that it doesn't work.
I have tried changing uri_protocol to all 5 options but no change. I also tried putting .htaccess file to var/www instead of var/www/my_app but no change either.
I keep getting that stupid 404 Not Found error when i try to access controlers without index.php prefix.
Any ideas?
EDIT: I checked phpinfo on server and found that mod_rewrite is in loaded modules.

The mod_rewrite module can have a couple different extensions. Your Debian server might use mod_rewrite.so instead of mod_rewrite.c.
That said, if you know mod_rewrite is enabled, and your application isn't being widely distributed and needs to check for it, you can safely eliminate the if checks.
You mentioned commenting out everything except lines 3 and 7 -- you commented out the RewriteBase definition, which broke stuff.
Try something simple, and work from there:
RewriteEngine On
RewriteBase /my_app/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Also, one variation you can do if an .htaccess is being weird, is to change everything after index.php to a query string. Note the ? here:
RewriteRule ^(.*)$ index.php?/$1 [L]
You may or may not to change the uri_protocol config setting in CodeIgniter. My guess is you specifically won't, but it's info for others who are having .htaccess issues.

Related

Cakephp project not working on server

Currently working on a project and completed. Works fine in local. But when uploaded to server. It Doesnt work as it should be. CSS and JS and images are not linked. I checked all the .htaccess files in project folder and they seem fine. These are the codes in .htaccess files
in root
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
in app
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
in webroot
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]
</IfModule>
These files were still same since uploaded to server. I also went through some articles and questions to make sure that am not messing with .htaccess files. Then i found this issue.
in local when i tried to open /localhost/project/app/Controller/UsersController.php in local it returns error as it should be
But when i tried the same in server
The page actually seems accessed. Since its controller no output is found but i can be sure the Controller is accessed directly. I cant figure out what kind of issue am going through. Am quite new to this. Any help will be appreciated.
Cake creates tmp files under tmp folder. You must need to give permission read/write to this folder. After making your code live please make 777 permission to your tmp folder and try to delete all those files under sub folders. It may work and please share your results. You will find tmp folder under app folder.
Your problem is in the in root .htaccess it should be like:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ projectfolder/app/webroot/ [L]
RewriteRule (.*) projectfolder/app/webroot/$1 [L]
</IfModule>
The project works now(Have to contact support for enabling the mod_rewrite). I enabled
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
in config/core.php The problem is didnt have the mod_rewrite enabled in server. So enabling that in core supported the project to work without mod rewrite.
Thanks to
http://wwdj.wijndaele.com/getting-started-with-cakephp-without-mod_rewrite/
I had same problem, it was working on localhost but not on server, it was throwing 404 error.
It is because I had uploaded my website in subdirectory of sever root. I did many things to make it work but as I am using htaccess in root folder I found no solution on root level.
Finally I found a solution, edited existing htaccess of cakephp root folder and added "RewriteBase" after RewriteEngine on.
Full code:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /name_of_the_subFolder
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
Like if my project appear in 'xyz.com/one/two/cake/' then RewriteBase would be Rewritebase /one/two/cake/.
It worked for me.

Getting Symfony2 to Work on GoDaddy without app.php

I got my Symfony site installed on my GoDaddy production sever. It works fine when I use the url www.amcolan.info/Symphony/web/app.php/index. I want it to set it up to work as www.amcolan.info/index.
I altered the domain to point to the folder amcolan/Symfony/web via a GoDaddy control panel. It used to point to /amcolan which contains the working version of my site. After I got that set up, I installed the following .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
# Explicitly disable rewriting for front controllers
RewriteRule ^/app_dev.php - [L]
RewriteRule ^/app.php - [L]
# Fix the bundles folder
RewriteRule ^bundles/(.*)$ bundles/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
# Change below before deploying to production
RewriteRule ^(.*)$ app.php [QSA,L]
#RewriteRule ^(.*)$ app_dev.php [QSA,L]
</IfModule>
I got the code from another related question on this site and modified to my purpose. The original was intended to live in the Symfony directory. I then cleared the production cache and attempted to access a page. It resulted in an Internal server error. Are there any errors in my code? You'd think this would be well documented by Sensio as I imagine 99% of all implementations would have to do this. Now I'm just getting bitter.
As suggested, I tried the following code that came with Symfony:
<IfModule mod_rewrite.c>
RewriteEngine On
<IfModule mod_vhost_alias.c>
RewriteBase /
</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I also tried:
<IfModule mod_rewrite.c>
RewriteEngine On
#<IfModule mod_vhost_alias.c>
#RewriteBase /
#</IfModule>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
</IfModule>
I got the same error as before with both. To make sure I was getting to the directory, I added a index.php file to it and I was able to access it.
Update 2
After rooting around some more about goDaddy specific issues, I found a post on a goDaddy forum saying the RewriteEngine is already on. I deleted that code without affect. I then decided to try this:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://www.amcolan.info/app.php/index [QSA,L]
That got it to work although I suspect not correctly. I had first tried it without the index after app.php/. That got me into symfony, but generated a get error. It appeared to be because of a null argument so I added the index. So, regardless of what someone might enter after www.amcolan.info, it's going to go to the index. Once you are on a Symfony page, you can navigate to other pages in the site. So now I have three new questions:
Any idea to where the web server is pointing when it reads the .htaccess file? You would think in the /web directory as that's where the file lives. Since just specifying app.php instead of the full path didn't work, it must not be the case. Would it be the base of my site?
After the successful redirection of www.amcolan.info, the resulting displayed URL is www.amcolan.info/app.php/index. I'd like to not see the /app.php in the URL, but I suspect that's not possible in as much as it is the actual destination. Is that a correct assumption?
How do I get www.amcolan.info/somepage to go to www.amcolan.info/app.php/somepage rather than the hard coded index?
Update 3
I thought I was stuck, but then I tried:
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php/index [QSA,L]
That got rid of having to use the full URL and now the destination pages no longer display the app.php. I have a new problem: just specifying www.amcolan.info causes the get error mentioned above. Specifying www.amcolan.info/somepage no longer takes me to the index, but to the specified page. Stay tuned, I may be able to solve my last problem with a little more digging.
Update 4
I fixed the last problem by adding the following to my routing file:
nopage:
pattern: /
defaults: { _controller: ZetchoAmColAnBundle:Default:index }
requirements:
_method: GET
I think I'm a happy camper now.
index action is not necessary. You can easily configure any action for root routing as well.
Here is my full .htaccess file on GoDaddy that finally works. It works only for prod config (app.php), app_dev.php is not working well, but that is OK for me since it is used for production environment.
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php/ [QSA,L]
</IfModule>

fuelphp htaccess for multiple app directory not working

I have a directory structure like below.
public_html/
/abc/
/xyz/
/pqr/
there is a index.php in each these directories, abc,xyz,pqr.
now whenever is there any request like domain.com/abc/def/ghi should be rewritten to domain.com/abc/index.php/def/ghi
domain.com/xyz/def/ghi => domain.com/xyz/index.php/def/ghi
domain.com/pqr/def/ghi => domain.com/pqr/index.php/def/ghi
What should be the .htaccess file and where it should be placed?
I have .htaccess file in each directory(abc,xyz,pqr) like below, but it is not working. it is showing 404 page not found. Please guide me to handle all these rewrite conditions.
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
But this is not working... If this is right .htaccess then please tell me if there is any other server side problem. I am setting up this on CentOs server.
You will probably need a RewriteBase /abc to deal with the subfolders.
I had problem with my directory access, I was needed to update the access for content directory(domain.com) in apache config file(httpd.conf)

CakePHP HTAccess 500 Internal Server Error, 404 Page Not Found errors

I'm using CakePHP 1.2 Version and When I upload my site on Live Server, it gives me 500 Internal Server Error
When I check mod_rewrite in phpinfo function, its not visible, but on same server another Joomla site is running perfectly fine without any problem of htaccess or path rewrite issue with AceSEF Component of Joomla for htaccess page / paths, so I believe as this is Shared server it must be that way.
I have tried different options like adding 'RewriteBase /' in root .htaccess file or trying the same in app/webroot/.htaccess files as well but no solution works for me.
Even when I write, 'RewriteBase /' in root .htaccess and app/.htaccess file, error changes to 400 Page Not Found. I don't know why.
Below is the .htaccess code:
root .htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
</IfModule>
app/.htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
app/webroot/.htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>
I have read through some links like: Apache-and-mod_rewrite-and-htaccess though not much helpful
Any answer or solution for this error? Much appreciated !!
Thanks
Check if the rewrite module is linked in the enabled modules of apache. Like you said it isnt listed in phpinfo() so the module maybe isnt enabled and joomla has some workarounds.
(use following commands at your own risk, you need root access)
under debian/ubuntu; apache2 enable the module like that
cd /etc/apache2/mods-enabled/
ln -s ../mods-available/rewrite.load rewrite.load
you have to restart apache2
service apache2 restart
Then the module should be enabled! So try again.
Alternatively, tell the url you try to open!

Why $_POST is empty when using [QSA] in .htaccess?

I've got the following in .htaccess:
RewriteCond %{REQUEST_URI} !app/index\.php$
RewriteRule ^(.*\.htm)$ index.php?url=$0 [QSA,L]
Everyting works great but result URLs have empty $_POST.
I'm 100% sure that it's mod_rewrite bug, not HTML or PHP because when I change [QSA,L] to [L] it works great. But I really need QSA.
It happens at about 30% hostings so this may be some Apache config option.
What about modifying your rule in this way. Does it change anything?
RewriteRule ^(.*)\.htm$ index.php?url=$0.htm [QSA,L]
by default,.. maybe apache not enable mod_rewrite, try type this on your console
sudo a2enmod rewrite
sample my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
I had exactly this issue. It works on one server then not the next. Annoying and time consuming to say the least!
After a lot of checking using this php:
foreach ($_REQUEST AS $key => $value) echo $value."<br>";
at the top of the index.php to check what values were being sent from the htaccess file, (and many other checks I will not go into!) I eventually found you need to specify "RewriteBase"
Adding RewriteBase / to the top of the htaccess file made it work on the all the servers I tried.
(also, remember to set to: RewriteBase /folder-where-file-is/
where "folder-where-file-is" is the location of the index.php file if in a sub-folder)
Hope it helps you - knowing this would certainly have helped me many many hours ago!

Resources