A non-technical owner of an authority site with 1000s of asp/aspx pages decided to rebuild the site using WordPress on a new cPanel server. The original site was on a windows server and built with ASP.net. The problem is that they now had lots of dead external links going to *.asp and *.aspx pages that no longer existed.
I can get the static, mostly html content from the old site and wrap a php template derived from the WordPress template around it
I've added the following lines to .htaccess file so that asp and aspx files should be able to use php code, but this is not working.
AddHandler application/x-httpd-php .asp
AddHandler application/x-httpd-php .aspx
Any suggestions about getting php code to execute with files ending in .asp/.aspx on a linux host?
You can also set mime type handler using a RewriteRule
Try :
RewriteEngine on
RewriteRule ^.+\.aspx?$ - [H=application/x-httpd-php5]
x is optional in the pattern above ,so it matches both .asp or .aspx .
Related
I am designing a website that requires me to show the outputs of a mysql database on a webpage written in html. However my browser doesn't seem to recognize the php scripts within the html file and returns blank values where their should be details. The scripts worked fine in the .php files but have no effect when included in the .html files even after creating a .htaccess file as instructed in previously asked questions. Is there anything else that can be done to solve this issue?
There are two methods (that I've encountered) of changing the environment on an Apache server via .htaccess to allow PHP scripts to be processed in .html files, depending on the configuation. Whichever of these you've attempted, try the other.
AddHandler application/x-httpd-php5 .php .html .htm
Or
AddHandler cgi-script .html
SetEnv PHP_EXTENSION .html
I've searched all over the internet and can't seem to find a solution to my problem. I want to be able to "call" a php file from an html file and display the string returned:
html_ONLY_file.html
...
<h1>GetHeader.php?type=main</h1>
...
GetHeader.php
if($_GET['type'] == 'main')
print 'Some header to display'; //or echo 'Some...';
exit;
I've done this for images, img src="image.php?file=file.jpg", where image.php does a header(...) and readfile(...) return but I do not know how to do this for simple text. I'm not looking for DOM or anything too involved, if I have to I will. I want to know if there is a simple solution. It's generating the html side that I'm lost on.
In case you want to know, I am doing this because I once used a <#virtual include=...> to call for a php file from my .shtml file. Well, the hosting company decided to change mod_security and now I cannot include any php files (I've already tried everything). Including html files works fine and so I am changing this part of the website around so I don't have to rename files because the site is for a small business that is now ranked highly on Google for its geographical area. If I change the file names, shtml to php, then I believe the Google ranking drops (don't comment on this part unless you are damn sure you are 100% correct).
If you can edit the .htaccess file you can add a line in your .htaccess file that will mean HTML files will be parsed as if they were PHP.
If your server is running PHP as an apache module:
AddType application/x-httpd-php .html .htm
If your server is running PHP as CGI:
AddHandler application/x-httpd-php .html .htm
Source: http://www.besthostratings.com/articles/php-in-html-files.html
Once you've added that your html_ONLY_file.html could look like:
<h1><?php print "some header"; ?></h1>
And it would function just as if it were a .php file.
Alternatively, you could convert all your files to .php and add redirects into the .htaccess file like so:
rewriteRule ^somefile.shtml$ somefile.php [R=301,L]
rewriteRule ^another-file.shtml$ another-file.php [R=301,L]
This effectively says to your server "whenever a user requests somefile.shtml, act as if they requested somefile.php instead". The R=301 is the most important part with regards to Google rankings. This tells Google (and anyone who requests the .shtml file) that it's permanently moved to the new location somefile.php. This transfers all / almost all of the ranking power from the old location to the new location.
Source: http://moz.com/learn/seo/redirection
I'm working on an old site, and I want to add cookie functionality in order to allow people to use the mobile site, but also opt-into using the full site if they want. The site is currently all .htm files, and I can't with the budget go in and change every link to .php so I tried adding this to my .htaccess file
AddType application/x-httpd-php .htm
This is causing the browser I'm using (Firefox) to ask me to download the file. It says it's a application/x-httpd-php file, so I know the .htaccess file is working. When I was building my home web sever, and trying to run a ruby on rails site I ran into the same problem because i hadn't set up ruby correctly and it wasn't rendering the file. But I have never run into a site that doesn't have some sort of support for PHP. Could this be caused by another problem. Or does that .htaccess file change break rules made by some web hosts?
Any support would be amazing! Thank you so much everyone :)
You need to add a handler for that type, otherwise the webserver isn't going to do anything with it:
AddHandler application/x-httpd-php .htm
That should be enough if you've already got phpv4 executing on your server. But you can also create a custom action explicitly:
AddHandler application/php-cgi .htm
Action application/php-cgi /path/to/php-handler
I am with new web host. The public_html folder of each domain I create is auto generated with an .htaccess that has the following line:
AddHandler php5-script .php
What is this for?
This just instructs PHP to handle files ending in .php by passing them to the PHP5 interpreter. Without this configuration in place, the web server may serve the files to the end-user's web browser as raw PHP code, rather than executing the code. That raises the dangerous possibility of exposing database login credentials or, or other secrets.
Using the same mechanism, you could configure the web server to parse files with other extensions besides .php as PHP scripts and hand them to the PHP interpreter. This is occasionally done to mask PHP scripts by naming them with .html extensions, for example.
# Interpret both .php & .html as PHP:
AddHandler php5-script .php .html
It tells php to handle any file with .php in the filename, even if it's not at the end. A file named smile.php.gif will be interpereted as a php file, which is bad if you are going to be using an upload script. This is because Apache allows multiple extensions in any order, so gif.php.jpg is the same as gif.jpg.php. I have heard the best way to select the handler is with FilesMatch. Of course if your web host has this in their httpd.conf you would have to 'remove' it using your htaccess before using the FilesMatch if you don't have access to httpd.conf.
The answer is that the htaccess tells the webserver to handle the php as php5-script and execute it.
Regarding the first answer, you will achieve your goal but it is a really bad practice and you should not allow html files to be executed as php due to huge security concerns.
I am trying to serve up an ics (ical) file via a url. Accessing my "ical.php" is fine. But many apps insist the url has a .ics extension. If I symlink "shamrock.ics" to ical.php then the raw php file is served up. I found a rewrite rule elsewhere in stackoverflow (RewriteRule ^(.*).ics$ $1.php [QSA]) but this doesnt work for me (other rewrites I use do work so I know the rewrite engine works).
Can someone suggest the next step or the best path to take to solve this.
I found the solution. And its not using rewrites. Simply add "AddType application/x-httpd-php .php .phtml .html .htm .ics" to the httpd.conf. I should have found that.