500 error while implementing MVC in apache server - apache

I am bigginer to php and i was trying to implement Model-View-Controller in php i updated allow override to all and created a .htacess file and wrote the following quotes in it,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?url=$1 {QSA,L}
but i gave me 500 error and i went straight to apache error log and got these errors:
[Mon Apr 09 01:18:36 2012] [alert] [client ::1] C:/wamp/www/.htaccess: Invalid command 'RewriteEngine', perhaps
misspelled or defined by a module not included in the server configuration
I googled and googled but cant find it, i just want to pass all the request to index.php file i watched a video on youtube it was working fine in his computer but not on mine, he told i should modify something in php.ini but i don't know whats that, if i write the following in .htacess:
ErrorDocument 404 /404.php
ErrorDocument 500 /500.php
and goto url that dont exists, then it is controlled by 404.php but it i tried to write the first script then i gives me 500 error every time... Previously i also tried to install zend framework but still there was same error....
I apologize for my language,,,
thanks in advanced... please help...

Is your rewrite module in apache enabled? You can enable it in httpd.conf file in your installation dir. If you are using windows just uncomment the rewrite module line and restart your apache.
You can google "enable apache rewrite" for more information.

You need to enable mod_rewrite. Either by 'a2enmod rewrite' or by adding manually to httpd.conf

Related

How can i write if condition statement in htaccess - Apache 2.2.15

I'm using a couple of folders outside Wordpress and if a file doesn't exist i want to show a custom 404 file (not the 404 standart Wordpress page). In these folders i have a .htaccess with only 2 lines "RewriteOptions Inherit" and "ErrorDocument 404 /err/404.php". It's working, but the problem is that sometime some ads banner are not using their domain in their script, and i have errors in my log.
[the_date] [error] [client IP] File does not exist: /home/admin/web/my_domain.com/public_html/folder_outside_wordpress/undefined, referer: http://my_domain.com/folder_outside_wordpress/my_file.php
Basically, if in their scripts is something like /folder/file.php instead of http://ads-domain.com/folder/file.php i got errors in my log file, as is right to be because im using RewriteOptions Inherit.
So, my point is to use line "RewriteOptions Inherit" only when the requested file is missing, something like this.
if (status == 404)
{
RewriteOptions Inherit
ErrorDocument 404 /err/404.php
}
Apache version 2.2.15
I have found another option without using RewriteOptions Inherit
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ /err/404.php [L]

symfony2 application on godaddy: no input file specified

I deployed a symfony2 application on godaddy and I got this error: no input file specified. After some research I managed to solve with some changes on .htaccess file:
DirectoryIndex app.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /app.php/ [QSA,L]
</IfModule>
this works but only for urls like /mycontroller, I still get errors when using urls like /mycontroller/newaction. what else can I change to manage it working? thanks
Here is a good post how to fix that problem.
When getting started with Symfony2 using Apache and fast-cgi for PHP, you may get the following message come up when trying to open up
the /app_dev.php/demo URL.
No input file specified. This occurs because the url rewrite module isn’t passing along the pathinfo details properly to the fcgi
php. Here’s how you can fix it.
1.) Open the relavent php.ini file
2.) Look for the cgi.fix_pathinfo setting.
3.) You’ll most likely find it set to 0.
4.) Change it so that it reads cgi.fix_pathinfo=1
5.) Save the changes. Restart Apache.
6.) Try loading up /app_dev.php/demo/. It should work now.
http://wilt.isaac.su/articles/symfony2-no-input-file-specified-

Explain .htaccess rules. Doesn't work for me

I have hierarchy structure of file as below:
/public_html/directory/
/public_html/directory/index.php
/public_html/directory/file.php
I want to forward the request to the most appropriate link. For example,
mydomain.com/directory/ to mydomain.com/directory/index.php
mydomain.com/directory/file to mydomain.com/directory/file.php
If 404 or 500 error occurs then forward it to /public_html/error.php
For this I have written following code in .htaccess
Options +SymLinksIfOwnerMatch -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# don't touch /forum URIs
RewriteRule ^forums/ - [L,NC]
# hide .php extension snippet
#To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+).php [NC]
RewriteRule ^ %1 [R,L]
# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*?)/?$ $1.php [L]
ErrorDocument 404 /error.php
ErrorDocument 500 /error.php
It works properly if I make requests as mentioned above. But if I request for page mydomain.com/directory/file/scrap then it generates Internal Server Error
I think its because file is not a directory. But I don't know how to solve this problem here. Please suggest.
Also one more line is mentioned in the error output by server regarding ErrorDocument for 500 in the end. The complete output is as follows:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.
Please contact the server administrator, root#localhost and inform
them of the time the error occurred, and anything you might have done
that may have caused the error.
More information about this error may be available in the server error
log.
Additionally, a 500 Internal Server Error error was encountered while
trying to use an ErrorDocument to handle the request.
This is happening because the %{REQUEST_FILENAME} -f condition also checks for "path info" style requests. So when you request:
mydomain.com/directory/file/scrap
The rewrite engine will see the file /directory/file.php and assume that you're making a path info style request, e.g. /directory/file.php/scrap
This causes the rewrite engine to loop.
You need to change that condition to:
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_URI}.php -f
Oh, also, as for the ErrorDocument thing, I'm pretty sure that what's happening is the rewrite module is completely ending the URL processing in the pipeline. That means, directives that get applied at the end of the pipeline will never get applied if mod_rewrite flips out and ends all the processing. That's why your ErrorDocument directives aren't being applied. If you fix the rewrite issue, you'll notice that the 500 error document will work again.
Based on the configuration above, I would say there is a problem with /error.php.
Assuming there is no scrap.php, mydomain.com/directory/file/scrap will not get rewritten.
The 500 error also mentions that the error was encountered while trying to use an ErrorDocument.
Try a static error.html instead of a dynamic error.php to narrow the problem down.
You could also log the rewrites to verify that they are working correctly:
RewriteLogLevel 9
RewriteLog /var/log/httpd/rewrite_log

RewriteCond: unknown flag 'QSA'

When configuring Restler it suggests creating the following re-write rule:
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^$ index.php [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [QSA,L]
</IfModule>
I have put this into a .htaccess file in root of my REST directory but I'm getting a 500 Server error when this rule is being fired. The error message the apache error log is:
[Wed Oct 10 10:39:30 2012] [alert] [client 127.0.0.1] /public/api/.htaccess: RewriteCond: unknown flag 'QSA'
[Wed Oct 10 10:39:30 2012] [error] [client 127.0.0.1] File does not exist: /public/favicon.ico
I assume the lack of a favicon.ico file can be ignored but I am concerned about the "unknown flag 'QSA'" error. I know very little about rewrite rules so any help there would be appreciated.
For those familiar with Restler, I am using 3.0.0rc2 (if that matters). Also it's worth pointing out that using the explicit call to index.php works so much as I then get a 404 JSON error response (a positive improvement) but as indicated above if I rely on the rewrite rule then I just get a 500 Server Error:
http://localhost/api/index.php/say/hi - WORKS (gives JSON 404 error)
http://locahost/api/say/hi - 500 SERVER ERROR
It doesn't look like the error has anything to do with the rules that you have:
/public/api/.htaccess: RewriteCond: unknown flag 'QSA'
which says that the QSA flag is an unknown flag for a RewriteCond, followed by a favicon.ico not found so I'm guessing that it's unrelated to requests into your REST directory.
If you had AllowOverride None, then your htaccess file is simply going to be outright ignored. There are different aspects of configuration options that can be overridden inside htaccess files, None means, htaccess cannot override any configurations, so it'll just get ignored.
The QSA flag isn't needed at all here. You only need it when you are rewritting the query string and want to append the original query string to the end. By default, the query string is appended anyways.
Interesting ... I was looking into my JSON 404 message and found this post:
Restler always returns not found
It not only solved my 404 error but also helped to fixed the 500 Server error. The only thing I needed to do was change the http.conf's AllowOverride to All.
I'd still be interested if anyone could tell me WHY this is happening but the this does now work.

Friendly URLs EasyPHP

I'm trying to configure friendly URLs on my site, and get following error in my Apache error.log:
[Tue Mar 20 18:41:39 2012] [error] [client 127.0.0.1] script 'C:/EasyPHP/www/index.php' not found or unable to stat
I access my site like this: http://localhost/mysite
Site files are here: d:\Sites\php\projects\mysite\public_html\
My .htaccess file:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php
I'm using EasyPHP 5.3.9 and Yii framework.
I've also uncommented this line in httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.so
This has nothing to do with RewriteRule, it has to do with your EasyPhp installation. Just make sure that the website is properly configured (check for the vhosts configuration or maybe if there's only one site, the httpd.conf configuration).
Check the /protected/config/main.php file in the yii project and uncommnet the url manager. Here's some help -> http://www.yiiframework.com/doc/blog/1.1/en/final.url