Ok so I've recently installed to test Orbis CMS, and I love it, except two things - this being one of them.
Test page 'page.php' worked fine, great! Incorporated it into an existing html page and that's where I ran into the issue. Duhr, it won't run the php snippits.
Quick Google shed light that I needed to add a piece of code into the .htaccess file to allow the html file(s) to run the php code. Tried it, and nothing, didn't work, at all. Was going off this link (provided by Orbis) here: http://php.about.com/od/advancedphp/p/html_php.htm
When I did it for all pages it started doing funky stuff and asking me to download/open pages when I clicked the links throughout the site, but not every link.. ?? When I did it for the single test page it didn't work full stop.
Anyone got any ideas?
Cheers.
Why don't you just rename the .htm file to .php ? You can have normal HTML in PHP files aswell, just outside of the <?php ?>Tags.
.htaccess has to be allowed from your hoster, so that might be the reason why it didn't work.
EDIT: Then just replace the .htm File with a redirection to your .php file.
You can achieve this by <meta HTTP-EQUIV="REFRESH" content="0; url=http://www.yourdomain.com/yourfile.php">
Or if the .htaccess is run by the webserver you can do a redirect there:
Redirect /youroldsite.htm yournewsite.php (would be the better version)
You need to change your .html to .php.
as you mentioned that .htaccess is not working check these thing it may help you
Is .htaccess enabled?
It's unusual, but possible that .htaccess is not enabled on your site. If you are hosting it yourself, it's easy enough to fix; open your httpd.conf in a text editor, and locate this section
Your DocumentRoot may be different, of course
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/var/www/htdocs">
#
locate the line that reads..
AllowOverride None
and change it to..
AllowOverride All
Restart Apache. Now .htaccess will work. You can also make this change inside a virtual host, which would normally be preferable.
If your site is hosted with someone else, check your control panel (Plesk. CPanel, etc.) to see if you can enable it there, and if not, contact your hosting admins. Perhaps they don't allow this. In which case, switch to a better web host.
and also check that rewrite_module is marked
Rename your Files to .php or change your server configuration to recognize .htm files as PHP files, too.
Example (httpd.conf):
<IfModule php5_module>
AddType application/x-httpd-php .php .htm .html
</IfModule>
As an alternative you could setup mod_rewrite to route to your php file on specific URLs.
You need to change your .html to .php. You mentioned you need to keep the link equity from other sites to your .html pages. To get around this, simply add a 301 redirect in your .htaccess file.
//301 Redirect
Redirect 301 oldfile.html newfile.php
Related
My problem started when I was working with the .htaccess file to a directory trying to get php to run inside of html files. I tried ALOT of combinations of AddTypes and AddHandlers. I took them out and now my php files are being downloaded by the broswer instead of running. There are a few other questions on here that I have studied up and down, but they are not exactly my problem.
I'm fairly lost now, I've tried just about every combination of AddType and AddHandler. I've since decided to use mod_rewrite and just have all my files end in .php but I can't get them to run.
This is what I'm using to test:
<!DOCTYPE html>
<body>
<?php
echo("php working");
?>
</body>
</html>
Am I missing something? Luckily I made all my changes at a separate directory than the root so that the site still runs, but none of the php files in that folder can be viewed in broswer. What can I do? Any help is appreciated.
EDIT:
Just to make it clear, I was originally trying to be able to put php in my html files so I was messing around with handlers and addtypes. My server does have php. If I call a php script from a .html file, it runs. I just can't get a php file like the example I included above to open in brower ANYMORE, it used to open in browser. My fear is that I have messed something up by trying all the different handlers in .htaccess. I have since cleared my .htaccess file in hopes that would at least get me to square one, but it hasn't.
SECOND EDIT:
I went to the root directory and made a php file and it ran just fine so its definitely something I changed in the .htaccess for the particular directory. Is there anyway I can reset that directory?
have you made sure to install php correctly within apache?
if you are using php as a module, you need the following:
LoadModule php5_module "c:/php/php5apache2.dll"
AddType application/x-httpd-php .php
# configure the path to php.ini
PHPIniDir "C:/php"
or as a CGI binary
ScriptAlias /php/ "c:/php/"
AddType application/x-httpd-php .php
# For PHP 4
Action application/x-httpd-php "/php/php.exe"
# For PHP 5
Action application/x-httpd-php "/php/php-cgi.exe"
other things to consider, are the permissions set correctly on the php binaries, is the php.ini present and correct, have you restarted apache since installing php into apache?
lastly, php doesnt run within html files, you would need to set the following as pretty much the last thing in the apache config
AddType application/x-httpd-php .html .htm
Do you see the line like this in your htaccess file?
php_flag engine off
If yes, delete it.
One more thing that may help you understand what happened
The following piece of htaccess would make Php from being executed but rather downloaded as a text file
<VirtualHost *>
ServerName sourcecode.testserver.me
DocumentRoot /var/www/example
AddType text/plain php
</VirtualHost>
One more thing
I'm guessing that this topic was addressed once here-> htaccess downloading file instead of loading
I have a problem trying to hide .php extension from the url
I have been asked to hide it and because they are on a shared host i don't think i have access to .htacess so is there another way to hide it through a php function that i would call everytime an anchor is being selected?
Is this truly about hiding .php or is it more about having cleaner URLs?
If you truly can't access .htaccess (i.e. your host has this turned off via AllowOverride None) and assuming you also can't have your Apache conf settings updated for your VHost, the best you can do may be
http://example.com/page.php/my/clean/url
By default, Apache will send this URL to page.php even with everything else after it. This is the most common way of creating "cleaner" URLs without access to mod_rewrite.
.htaccess is what you would have access to on a shared server, as opposed to httpd.conf, which you wouldn't.
Put a .htaccess file in your document root with the following
FAIL
If your site stops loading, then you can use .htaccess :)
Of course, ^ that is a joke.
I have a site at
http://mgteurope.com
which I am transferring to a new hosting company, I set up the normal way using add-on domain, copied the database over and altered the config file to fit and then changed the name servers.
Problem, the site did not want to work as it should, I changed the name-servers back and using another domain name as to find a solution for now as seen in the URL below.
http://aylesburyfoodwall.co.uk/
The problem, .php extensions do not appear at mgteurope e.g. I can access mgteurope.com/admin and it goes to admin page on aylesburyfoodwall.com it must be /admin.php
I checked the .htaccess file and it uses
AddType application/x-httpd-php5 .htm .html
AddHandler x-httpd-php5 .htm .html
<Files .htaccess>
order allow,deny
deny from all
</Files>
I added a RewriteEngine On at the start of the .htaccess file and no luck
I have also compared phpinfo on both and there seems to be no major difference.
My second problem of the site on aylesburyfoodwall is that it does replicate the same actions on mgteurope. When you click on the links down the left side it should veiw those items only when logged in but it does not (it loads the page though as seen in the url at the top address bar) when not logged in, it should produce a 403 forbidden error.
I assumed it would be a straight forward transfer one from hosting to another.
New hosting is shared/reseller and not dedicated.
Advice welcome
AddType application/x-httpd-php5 .php
AddHandler x-httpd-php5 .php
I guess handlers should look like that....
And please paste the .htaccess file with mod_rewrite config.
Look at the server and php configuration, something's gotta be wrong if unauthorized users can view private pages. And bear in mind that you've got a serious security leak if this happened, so take a look at the way you authenticate/authorize users.
I recently played with a .htaccess file to make one server to parse PHP files. Yesterday I uploaded the same .htaccess file and tried to test a PHP file. But something went wrong: visiting my page the browser offers to download the the html page rather then viewing the page!
On the server the filenames end in .html.
I added the following to my .htaccess file:
AddType application/x-httpd-php .html
I tried to find the htaccess file, but once uploaded it just disappears from the root dir.
I tried to upload other scripts I've found browsing. I even tried to search for some problem on a hosting forum. Nothing helped.
Please help!
Try this
AddType application/x-httpd-php .php .htm .html
OR
AddHandler application/x-httpd-php .php .htm .html
And remove other overriding handlers for application/x-httpd-php after above code.
Right, firstly things first, what host do you use?
Also what ftp client you are using? Some by default won't display files starting with . such as .htaccess and .htpasswd, that's why it may appear that you didn't upload it. Also it might be that you don't have the rights to upload in the very root directory, try to go one directory up.
Also from my experience, hosts won't allow you to modify headers via .htaccess this way, because the allowoverride directive is off; instead have a look at url rewrites (via mod_rewrite), which allow you to do the same thing without modifying headers.
Your rewrite .htaccess file might look something like:
RewriteEngine On
RewriteBase /
RewriteRule ^(\w+)\.html$ $1.php [NC]
(Not tested though)
Using a rewrite will also mean that your files will in fact maintain the php extension, however they will be access via urls that include .html extension.
I'm trying to port a PHP site developed by another coder (who is no longer around) and I'm having a problem with the Apache Rewrite rules which are prompting a file download on the target server. I'm sure this is a simple problem, but I'm having some difficulty Googling an answer. I'm running on a (dedicated) Ubuntu Server with a standard installation of Apache and PHP5 and porting from shared a shared server where everything runs fine. No site files have been altered during the port.
The .htaccess file contains this code (only)
# Use PHP5 as default
AddHandler application/x-httpd-php5 .php
Options -Indexes FollowSymlinks
RewriteEngine on
RewriteRule ^html/(.*) /index.php?init=site\/$1\/$2\/$3\/$4\/$5\/$6\/$7\/$8\/$9
RewriteRule ^mykart$ /index.php?admin=true
RewriteRule ^mykart/$ /index.php?admin=true
RewriteRule ^mykart/(.*)$ /index.php?init=admin\/$1\/$2\/$3\/$4\/$5\/$6\/$7\/$8\/$9&admin=true
When I try to open the file http://www.mysite.com/html/#home the browser attempts to download the (index.php) file instead of displaying it, with the message
"You have chosen to Open
[dialog shows blank space here]
which is a: application/x-httpd-php
from....
"
I guess I must have missed something in either the PHP or Apache configuration, but what?
EDIT: To clarify, the server is running Apache2 and has several, functioning, PHP sites on it. Furthermore if I delete the .htaccess file and run a simple phpinfo display page everything runs fine, so it's not the execution of PHP per see.
I suppose that the MIME type application/x-httpd-php5 is not valid. I’ve tried it on my local machine and it caused the same behavior.
Have you tried application/x-httpd-php instead?
Looks like an Apache config issue, of course I could be wrong. Have you checked httpd.conf for the following lines:
# Add index.php to your DirectoryIndex line:
DirectoryIndex index.html index.php
AddType text/html php
I had a similar issue. Browser attempted to download links from php website, instead of loading them.
It wasn't Php interpreter issue for me, it turned out to be misplaced .htaccess file. However, I didn't realized that disabling the htaccess file solved the issue for hours, due to browser cache.
So, don't forget to clear your browser caches! And restart Apache.