Rewrite conditions and failure to load .php - php

While my website works fine on my local environment (MAMP) when I upload the files to my server (bluehost), I run into the following issue:
I have a link with a php get variable (i.e. /xxx.php?p=bob) that invokes a javascript function (popitup) that opens a pop-up window.
The link is structured as follows:
<?php echo "<a href='media_player.php?p=".$listen_now."' onclick=\"return popitup('media_player.php?p=".$listen_now."')\">"
The popitup function is defined as follows:
function popitup(url) {
newwindow=window.open(url,'name','height=700,width=375');
if (window.focus) {newwindow.focus()}
return false;
}
When the pop-up window opens, the page contents do not load, and I get the following message:
[an error occurred while processing this directive]
The main error log shows the following warning:
[Mon May 28 08:23:40 2012] [warn] RewriteCond: NoCase option for non-regex pattern '-f' is not supported and will be ignored.
The .htaccess file in my public_html folder does not contain any redirects or rewrites.
Any leads on how I might solve this issue are very much appreciated.

RewriteCond warnings come from Apache's mod_rewrite. You have a broken rewrite rule in either:
.htaccess (directory of .php file or in any directory up the tree to the system root)
Virtual Host configuration
main apache configuration
Find its location and fix it there.

Related

Apache with PHP serves a base file instead of 404

Problem: Suppose a URL is requesting a file that doesn't exist, e.g. mydomain.com/index.php/bogus
There is no folder named 'bogus' so I expect a '404 not found' response, but instead Apache sends the request to /index.php (which does exist). Why? How do I change it to respond '404 not found'?
I suppose that, in theory, Apache does this to let me generate a custom index page for the folder 'bogus' (which however does not exist). But in practice, by returning a page with 200 response, it is causing confusion to search engines and accidental visitors. My PHP code in 'index.php' is not expecting this URL and so it generates broken links in its dynamic navigation routines.
I've tried to disable indexes (Option -Indexes) and directory indexing (DirectoryIndex disabled) and removed .htaccess (AllowOverride None). None of these changed the response. I've searched stackoverflow and it has plenty of "how to serve a file instead of 404" but this is the opposite: I want Apache to return 404 instead of serving a PHP file from higher up in the file system.
My server environment is Windows Server 2008, Apache 2.2.22, and PHP 5.3. No mod_rewrite.
The solution that works is to add AcceptPathInfo Off to the Apache config file.
This directive controls whether requests that contain trailing pathname information that follows an actual filename (or non-existent file in an existing directory) will be accepted or rejected. The trailing pathname information can be made available to scripts through the CGI (common gateway interface) specifications.
When AcceptPathInfo is 'Off', the CGI parsing will keep the URL as one long string and look for a file in your filesystem to match.
When AcceptPathInfo is 'On', the CGI will separates the URL into a script name PLUS the following characters are information made available to the script.
The Apache core docs have more info: http://httpd.apache.org/docs/2.0/mod/core.html#acceptpathinfo
You don't have a folder named index.php, you have a file with that name. I think apache finds the file and decides it's found what was requested, so it serves the file.
In your index.php file, you can check that $_SERVER['REQUEST_URI'] is a valid request for index.php. If it isn't a valid request, you can use the PHP http_response_code(404) or header() functions to make your index.php return 404 for invalid URLs.

Apache forbidden error. But the index page works well

Well I have been having a tough time trying to figure out the reason for getting the forbidden error message on my wamp server.
I have a folder website_ink inside c:/wamp/www/ folder. when I access
http://localhost/website_ink/
the index page loads fine. But when i try to access any other page it gives me a forbidden error message.
The url i tried accessing was http://localhost/website_ink/cloud-plans.
This page does exist inside my root directory meaning inside website-ink/cloud-plans.php page does exist.
This is the error I find when visiting the url on browser
Forbidden
You don't have permission to access /website_ink/C:/wamp/www//website_ink/cloud-plans.php on this server.
Apache/2.4.9 (Win32) PHP/5.5.12 Server at localhost Port 80
This is the error message i found in the log file
The given path is misformatted or contained invalid characters: [client 127.0.0.1:60811] AH00127: Cannot map GET /website_ink/cloud-plans HTTP/1.1 to file.
I do not have any virtual hosts setup or anything fancy. Also I tried upgrading from Apache 2.2 to Apache 2.4. Currently I am using Apache 2.4.
Please help
The reason why it happens is you try to open "/website_ink/cloud-plans" instead "/website_ink/cloud-plans.php".
In case you want to use path wiht out file extension you need add rewrite rule to .htaccess or httpd.conf:
RewriteEngine on
RewriteRule ^/(website_ink/.*)/$ /$1.php [L,QSA]
Also you need mod_rewrite to be installed and enabled

Apache/PHP downloading index.php rather than displaying..?

https://coinsafe.io/
I recently purchased and applied an SSL certificate.
After getting it all set-up, when I go to the site it downloads the index.php file...
There is code in the file but I cleared it out to see if it was my code causing it, and it downloaded it again and it was empty as expected.
The weird thing is when it downloads, it's not a .php file and it's called "download"
How can I fix this?
Edit
I am now getting this error [Sat Nov 16 04:09:07 2013] [warn] NameVirtualHost *:80 has no VirtualHosts
when I try to start Apache.
Basically, if Apache is trying to send a PHP file to your visitor, it means that Apache doesn't realise that the PHP is a script file.
This in turn means that apache hasn't loaded the php module, even if it's installed.
If you've done nothing else, there should be some sort of hint in your apache error.log, usually located in /var/log/apache2/ on ubuntu.
Also, in ubuntu php, you should have sym-links to php.conf and .load in /etc/apache2/mods-enabled/

How to check for mod_rewrite on PHP CGI

I am on shared host and PHP is inatalled as CGI script and that is all the problem i am not able to find whether mod_rewrite if enable or not
Note: I don't have any root level access so i can't much do with Shell.
I have tried the following :
1) checked in phpinfo() where i came to know about that this is the wrong place to look for in PHP-CGI.
2) I have tried getting it from apache_get_modules which agi does not work in PHP-CGI :(
3) I have tried :
if (strpos(shell_exec('/usr/local/apache/bin/apachectl -l'), 'mod_rewrite') !== false) {
// mod_rewrite is enabled
}
which is asking for path to apache and i dont have this info SHELL cant reply to me and $_SERVER has nothing.
4) I have checked with RewriteEngine On in .htaccess and after this my site is throwing 500 Internal server error may be because of RewriteEngine is not there, but i need this is written to show someone.
Any body has any idea how to check get this DONE.
Thanks
With PHP CGI there is no easy way to find out whether mod_rewrite is available or not on the server.
So, you need to find out it by making a test call to the server. You can use the following steps for this method,
Create a directory named mod_rewrite_test on the server.
Add .htaccess file in this directory with the following code,
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /mod_rewrite_test
RewriteRule .* mod_rewrite_test.txt
</IfModule>
a. first line tells apache to execute the below code only if mod_rewrite is available,
b. second line enables rewrite engine,
c. third line sets rewrite base directory path which is from DOCUMENT_ROOT
d. forth line returns the content of mod_rewrite_test.txt file to any request sent to mod_rewrite_test directory.
Create a file named mod_rewrite_test.txt in the same directory. Write ok in this file and save it.
Now, using CURL in your php script, call the URL similar to,
http://www.your-domain.com/mod_rewrite_test/test.php
and check the response.
So, as per our .htaccess code, if mod_rewrite is active and working on the server,
it will return the content of mod_rewrite_test.txt file i.e. ok even though the test.php file does not exists.
Otherwise, it will return 404 - Page not found error.
To check if mod_rewrite module is enabaled, create a new php file in your root folder of your server. Enter the following
echo phpinfo();
And access file in your browser.

File does not exist: sys_cpanel php

I am trying to set up my website on VPS (Virtual Private Server). When I browse a static file like abc.html it works well. However when I try to browse a file that has database connection I get 500 error: The request was not completed. The server met an unexpected condition.
So I thought my mysql credentials would be wrong. But they seem to be correct. When I go into CPanel and check the logs I find this:
[Sat Jun 02 08:19:26 2012] [error] [client XXX.XXX.XXX.XXX] File does not exist: /home/abv/public_html/abv/Connections/sys_cpanel, referer: http://XXX.XXX.XXX.XXX/~abv/abv/Connections/PowerCMSConnection.php
Googling it suggests that I have something wrong in my .htaccess file. But if it would have been wrong then why would the files that don't use database connection work?
Anyways, this is my .htaccess file:
##########################################
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\$ $1.html [nc]
Redirect 301 /business.html http://www.something.com/corporate-production-video
Redirect 301 /events.html http://www.something.com/london-videography
Redirect 301 /property.html http://www.something.com/property-on-video
Redirect 301 /weddings.html http://www.something.com/weddings-videographer
Redirect 301 /contact_us.html http://www.something.com/production-companies-music-video
Can somebody suggest what the error can be?
If your browser support Private Browsing (Fifefox, Incognito for Google Chrome and InPrivate for Internet Explorer), try opening the site after initializing such private browsing mode.
A while ago when I was configuring my webserver for redirects, it turned out that the browser saved the first redirect setting (301 means permanent redirection), and even though I altered the configuration and rebooted the server, my browser was using the same, bad, locally cached data. The issue for me was cleared after checking in private browsing mode.

Categories