Codeigniter Project in live server always gives 500 Internal Server Error - .htaccess

I've trying to solve this issue for the past 24 hrs but nothing seems to work. It works fine on my local with the following htaccess code.
Options -Indexes
RewriteEngine On
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /ocr/index.php/$1 [L,QSA]
But when I copy my project into /ocr dir of public_html dir in the server with the same htaccess code it gives 500 Internal Server Error.
Can anyone help me fix this issue. Any help will be highly appreciated.
P.S to moderators. Please don't flag this as duplicate question as I tried almost all answers found here regarding this issue and none worked.

Uff.. took the hell out of me to fix this issue. Spent more than 48 hrs trying random stuffs with .htaccess files. There were no error log files generated inside application/logs dir. So, that gave me a massive headache.
But finally from somewhere it hit my head that I should see the error log files from cpanel and it was where I found whats causing the issue. My project dir had 777 permission and that was the reason. Then it worked when I changed the dir permission to 755.

Related

Using htaccess to rewrite a get variable

I've been trying to figure this out for a few hours but stumped. I am trying to rewrite the url with a get variable to make it seem like a file. I've tried many different answers I've seen to no avail. Is it possible that I don't have a certain setting turned on? Your help is greatly appreciated!!
I am trying to redirect
www.site.com/products/?q=coconut
to
www.site.com/products/coconut
so far this code gives me a 500 error
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /products?q=$1 [L,R=301]
Wow dumb mistake on my part, but leaving this up just in case someone else is pulling their hair out. I had a faulty php code which lead to a 500 error.

.htaccess redirect in folder on domain affects same named folder in subdomain

I recently changed a site I've developed to use a Wildcard SSL certificate but I'm having an issue with .htaccess ReWrites in the domain.com/projects folder affecting the cms.domain.com/projects folder.
In the www.domain.com/projects folder is:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^([^\.]+)$ $1 [NC]
RewriteCond %{REQUEST_FILENAME} >""
RewriteRule ^([^\.]+)$ /projects/project.php?id=$1 [L]
When an SEO friendly project url e.g. www.domain.com/projects/project-title gets sent to this folder it is directed to the project.php page where it can be displayed.
This works fine, but I came across a problem in the subdomain cms.domain.com/projects, this folder and all its contents display a 404 error, even though all the files are there. I know this .htaccess file is the issue because I have changed the cms.domain/projects folder name and the sub directories appear and I've also removed the code from the .htaccess file and the cms.domain.com/projects folder appears.
I have tried, many of the suggestions found here and else where adding RewriteCond %{HTTP_HOST} ^www.domain.com$ and denying the cms.domain.com url but nothing works, and the projects folder in the cms remains stubbornly in 404 land. I've been looking at this for several days and have found nothing similar on the Interweb. Any help I can get would be greatly appreciated.
Thank you for all the replies so far.

Codeigniter: session destroy works well on one server but not in another server with same code and .htaccess file code

Hi guys i am trying to run my first web product live from last two days but i am stuck with (session or .htaccess or cookie problem).
Main problem i am facing is
I have the same code in two different servers both are running on php 5.4 version. and i have kept same .htaccess file in both the server.
What i tried till:
first i thought it's a problem with htaccess and then changed htaccess to
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Options -Indexes
Then i thought it may be problem with cookie or session of codeigniter i read many blogs and answers and changed some times the session variable gets destroy and some time not. and on some controllers the session variables are set and in some controllers they are not set.. Then last i uploaded to another server and there its working perfectly.
email and password to login for both sites
email: demoadmin#gmail.com
password: demoadmin123
The question may be not proper to ask on Stack overflow but i couldn't able to get other places to get a solution. it will be lot helpful if some solutions worked.
If any body suggest good forums to discuss the problem please comment it.
Thank you in advance.

Rewriting URL with .htaccess local in XAMPP

My .htacces begins with
RewriteEngine on
RewriteBase /
(I tried it also without RewriteBase...)
I tried all of the following rewriting rules to rewrite the URL
index.php?page=news
to
/blog
RewriteRule ^/?([-A-Za-z0-9]+)/([-A-Za-z0-9]+)/blog$
index.php?page=$1 [L]
RewriteRule ^([^/]*)/blog$ /sites/blog/index.php?page=$1 [L]
RewriteRule ([a-zA-z]+)/([a-zA-z]+)/blog$ index.php?page=$1 [L]
Nothing works - no error. Mod_rewrite is installed and working. I restarted Apache and MySQL everytime I changed something in my .htaccess.
I also want to change my URLs which looks like this... index.php?page=single_news&category=release&id=9&headline=Beastie%20Boys%20III
...into: blog/release/9-Beastie-Boys-III
I am lost. Hope you can help me.
First of all, upload your .htaccess and other files (whole project) to some working, ready hosting server. And check, if your rewriting works OK there. This will let you know, if this is problem with .htaccess or XAMPP itself. I had many strange problems with using .htaccess locally, under XAMPP, that were magically gone, after files were uploaded to Internet hosting.
For example, I don't have working autorization using .htaccess locally, because right after I provide correct login and password I see exactly the same error message as you mentioned. As for me, I'm more than sure that this problem is purely related to incorrect interpretation of .htaccess done by XAMPP (as everything works like a charm on production server), not by some mistakes in .htaccess contents.
I wasted (too) many hours on finding solution and left it. For right now, if I'm developing locally, I rename ".htaccess" to "htaccess", so it is ignored by XAMPP (Apache on-board of it) and re-enable it only when deploing files to production server. This approach maybe isn't to professional, but it saved me a lot of time and stress! :]
On the other hand, if your hosting also fail with the same symptoms, then you'll know, that this is not XAMPP releated problem and you have something wrong with your syntax.
Take a look here for a similar problem reported on StackOverflow.com, where (as I think) the cause is the same as in your issue.
Here's the solution to change links from http://www.domain.tld/index.php?page=blog to http://www.domain.tld/blog is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^\w+$ index.php?page=$0 [L]
RewriteCond %{THE_REQUEST} index\.php
RewriteCond %{QUERY_STRING} ^page=(\w+)$
RewriteRule ^index\.php$ /%1? [R=301,L]
and for links like: http://www.domain.tld/index.php?page=single_news&id=1&headline=This%20Is%20A%Headline
the solution is:
RewriteRule ^blog/(\d+)-([\w-]+)$ index.php?page=single_news&id=$1&headline=$2
After using this code, links looks like this: http://www.domain.tld/blog/2-this-is-a-headline
For your first question, try this:
RewriteEngine on
RewriteRule ^/blog$ /index.php?page=news

.htaccess - Localhost working in a folder problems

I'm working localhost on my mac with MAMP. And I'm trying to do some mod_rewrite with .htaccess. I think all my problems is about that I'm working on a URL like this: localhost:8888/folder/index.php.
How do I either "remove" the /folder/... Or make .htaccess work with /folder/ having in mind that I wanna remove it as soon as my project goes live? *I would prefer to "remove" the /folder/ to make it look more like when my project goes live.
If I am trying to for example "remove" the index.php like this:
#Removes index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]
It's jumping all the way back to root: localhost:8888/ instead of localhost:8888/social/.
Had the same problem and just found a solution.(I know i may be late to this post, but might help some else)
The problem I had was with the my local web enviorment. I tried it on the server and everything was working! So found out that I just needed to set up the Virtual Hosts for my sites in apache and everything worked great!
I did this with the help of this stackoverlfow post: How to set root directory to a subfolder and this article on how to do this on a windows PC: Setting up Virtual hosts in win 7
Hope it helps,
Cheers!

Resources