I was following a video tutorial on Youtube from phpacademy, https://www.youtube.com/watch?v=hxWYeCGa-PA&index=6&list=WL to make a dynamic RSS feed. In order to do that I need to be able to use php inside my rss file.
In this video the guy mentions adding the following line to the HTTPD-Conf file in order to allow this.
AddType application/x-httpd-php .rss
I contacted my web host 123-reg and asked them
Do I have access to the HTTPD.Conf file, or is it already configured to allow this.
I am looking to add the following line of code to the file if it isn't already in there.
AddType application/x-httpd-php .rss
What options do I have?
They responded with the following
The HTTPD.Conf file cannot be accessed with a shared hosting package
as the one used to host the website for the domain vwrx-project.co.uk.
This file is already configured to allow RSS, however you will need to
enable it. You can try adding the handler into the .htaccess file.
Does this make any sense to someone, I don't really know what code I should be looking to add into my .htaccess file
You can use url rewriting (if your hosting supports this) to direct non-existing files and directories, with .rss extension to .php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)\.rss$ /$1.php [L,QSA]
Put all these lines into your .htaccess file and youtubefeed.rss will open youtubefeed.php, which you can program yourself.
After some more hunting around, and having looked up DaveG's code I wasn't sure it would do as I would have liked.
I have a file with a .rss extension for my rss feed, so from my understanding of the above code, it would redirect you from filnename.rss to filename.php where as what I was looking to do was retain the .rss extension but allow that file to read and interpret the php within it.
After some more searching I found that I could have used the original code from the video, and place it inside my .htaccess file instead on my httpd.conf file, I didn't realize that the code was interchangeable.
AddType application/x-httpd-php .rss // For older versions of php
Anyway whilst looking for this solution I saw some using the line of code below to achieve the same result, the only real difference being it is for PHP5 and later which is whats running on my server so AddType is now AddHandler and we add a 5 to the end of php
AddHandler application/x-httpd-php5 .rss // For use with PHP5+
Related
First of all, I am not trying to run php within a js script, there is a similar question on here that refers to a user trying to run php from inside a js script.
I have added many combinations of
AddType application/x-httpd-php .php .html
AddHandler x-httpd-php .html
to the .htaccess file in a higher level directory containing the .html file I want to run php in. This has not worked. (I am open to trying new combinations)
The is either not read at all or commented out when viewing the source in broswer.
My question is how to get to be run inside of an html file OR is there a better way to include php functionality in an html document without having the code in the same document.
Additionally my host uses cpanel if this helps anything.
I can elaborate on anything I need to, thanks in advance.
You can try to use mod_rewrite for that task:
RewriteEngine On
RewriteRule ^(.*).html index.php [QSA]
I'm trying to hide the fact I'm using PHP on one of my site pages and I'm wanting to run it through the PHP parser (just that page not them all) so I can call it filename.html as usual. I have tried a few Apache directives I found online and have a few in my .htaccess file (hotlinks and for a 404 page).
When i use one of the scripts (in my .htacess) for the PHP purpose, the page wants to be saved/downloaded (like a vcard does) and a box shows - with no page to view. Can anyone please help. I'm new to PHP but believe a module might be needed or that it could be to do with the config of my server.
You should leave the page with a .php extension and have Apache handle the file as a normal PHP file. Then use a RewriteRule in your htaccess settings to hide the php file as follows:
RewriteEngine on
RewriteRule ^yourfile\.html$ yourfile.php
There is no real need to hide the fact that you are using PHP, but if you really want to parse PHP in html files you need to edit your Apache httpd.conf file. Open it up in a text editor and find a group of lines that looks like this:-
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-httpd-php .php
(Yours may be slightly different)
Then add
AddType text/html .html
restart Apache and php in html files will be parsed.
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.
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 am trying to do the following in my web application:
<img src="static.example.com/image01.jpg?width=300&height=300" />
Is it possible to have my server (I use Apache in a shared hosting environment) run a PHP script when accessing a .jpg (or any filetype that I chose) instead of just serving the file?
I know that the PHP script has to set the right headers etc, I'm just wondering how it can be run in the first place.
I know this can be done as so :
<img src="static.example.com/get_image.php?name=image_01.jpg&width=300&height=300" />
but that's not how I would like to have it.
You could use mod_rewrite provided you are in a subdirectory, or that is all your other static.example.com will be doing.
Add something like this to your .htaccess in that subdirectory.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{query_string} ^height=([^&]+)&width=([^&]+)
RewriteRule (.*\.jpg|.*\.png|.*\.gif) controller.php?name=$1&height=%1&width=%2
</IfModule>
EDIT: Try the above. Like everything else, untested... :)
The order of the GET parameters becomes important.
test.jpg?height=100&width=120
should get turned into
controller.php?name=test.jpg&height=100&width=120
Another approach would be to make apache serve .jpg as php scripts for that directory.
Just look in your httpd.conf or php.conf and look for .php. Find that directive, and duplicate it within a <Directory> for .jpg.
I've never actually tried this for a single directory, but ultimately it would be faster than the mod_rewrite route.
Something like:
<Files *.jpg>
SetOutputFilter PHP
SetInputFilter PHP
</Files>
AddType application/x-httpd-php .jpg