htaccess Rewrite Rule for php to png stopped working - apache

I have created several php files that dynamically build images for user rankings. I included an htaccess file in the image directory to translate the php files into png files so that the phpBB board would allow them to be used as ranks. Up until yesterday everything was working fine. I was using the following code in the htaccess file:
RewriteEngine On
RewriteRule ^rodeojones.png$ rodeojones.php
RewriteRule ^marine.png$ marine.php
RewriteRule ^treble.png$ treble.php
RewriteRule ^major.png$ major.php
RewriteRule ^hyghway.png$ hyghway.php
RewriteRule ^zypher.png$ zypher.php
etc... Now, all of the sudden, it isn't working. I am guessing this isn't the most efficient code and therefore it is no longer working for that reason, but I am not sure. This was my first adventure in php so I am lost as to a solution. Any help would be greatly appreciated. Thank you :)

Try something like this:
Options +FollowSymlinks -MultiViews
RewriteEngine on
RewriteRule ^(script)/([^.]*)\.php$ $1/image.png [L]
Hopefully will help you, though needs to find more specific to your scenario !

Related

Writing htaccess rewrite rules

I need help in making this htaccess rewrite rule
Suppose I have this url http://test.com/new.php?code=6789767897879&channel=1432
I need to make it http://test.com/live/6789767897879/1432.m3u8 where code and channel number are variable
So far I tried this with no luck but it keeps giving me no page found.
RewriteEngine On
RewriteBase /
RewriteRule ^/live/(.*)/(.*)?$ /new.php?code=$1&channel=$2
I am sorry but I am a beginner. Any effort is appreciated. Thanks again
Could you please try following, written and tested with your shown samples. Please make sure you clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^live/([^/]*)/([^.]*)\.m3u8/?$ new.php?code=$1&channel=$2 [NC,L]

Simple rewrite not working (.htaccess)

I'm trying to work out a bigger problem, which I believe lies in my .htaccess file. So I stripped it down to the following for testing purposes:
RewriteEngine on
RewriteRule ^sandbox/htaccess/one.php$ sandbox/htaccess/two.php
I'm simply trying to get requests for
http://example.com/sandbox/htaccess/one.php
to go to
http://example.com/sandbox/htaccess/two.php
However, this is not working. I simply see one.php.
I can confirm that .htaccess file is being read.
What am I missing to get this simple example working?
Try this, it will work
RewriteEngine on
RewriteBase /
RewriteRule ^sandbox/htaccess/one\.php$ /sandbox/htaccess/two.php? [L,R=301]

Apache URL rewrite change file extension from .htm to .cfm

First let me apologize if this has been asked/answered before. I did a search and could not find what I was looking for. Some questions were close but just not enough. Again apologies for duplication.
Second, my work has always been with IIS and as such my apache knowledge is limited so again, my apologies for asking for a little extra "hand holding" as I learn how to address this issue. Much thanks to any and all for your help.
Now for my question...
I have http://www.mycompany.com/internalUser/[className]/beginClass.htm where [className] is dynamic, for example French101 or Biology210 but each always have beginClass.htm
What I need to do is have a URL rewrite that changes beginClass.htm to beginClass.cfm
What I am not sure of is where should this rewrite code go - in the httpd.conf or .htaccess file within /internalUser folder.
Furthermore, I have tried the following example adding it to the directory tag created for internalUser
-- Copied from httpd.conf
Alias /internalUser "c:/iUser/training"
<Directory "c:/iUser/training">
RewriteEngine on
RewriteBase "/iUser/training"
RewriteCond "$1.cfm" -f
RewriteCond "$1.htm" !-f
RewriteRule "^(.*).htm$" "$1.cfm"
</Directory>
Also created in .htaccess file and neither is working. When I attempt to open the .htm it does not redirect or open the .cfm version. The .htm file is still being opened.
Thanks in advance for any and all help.
Use below for rewrite,
RewriteEngine On
RewriteRule ^internalUser/([^\/]+)/beginClass.cfm$ internalUser/$1/beginClass.htm [L]

htaccess doesn't load new js/css from another vhost

Ok, so here it is!
I have two virtual hosts, named main.aaa.com and static.aaa.com.
I have a htaccess rule in main.aaa.com that for each path that contains js|css|img|ico will load them from static.aaa.com.
This is the htaccess for main.aaa.com:
Options +Indexes
Options -MultiViews
Options +FollowSymLinks
# Turn on the RewriteEngine
RewriteBase /
RewriteEngine On
#
# Rules
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !\.(css|js|ico|img)$ index.html [PT,L]
RewriteRule ^(.+\.(css|js|img|ico))$ http://static.aaa.com/$1 [L]
What's going on is that everything works perfectly, absolutely perfect, but...
if I create a new file in static/js folder and try to load it in main.aaa.com index file, it just gives a 200 OK, file not changed, and by looking into it it seems that htaccess doesn't even bother to look for the file in static vhost.
I have changed file permissions to 755, all of the files have the same permissions and the same owner, only that the new ones that I create are not loaded.
Any help would be much appreciated! Thank you!
[EDIT]: I tried also to rename a file that is now correctly loaded, because I thought I am missing something about file permissions. Stopped working. Renamed it back to previous name and it loads. So, I am thinking, is there a history of files or something that I can clear? I am at the point to break something, anything!
Using ubuntu 14.04 LTS and apache 2.4 if that helps.
I have found a solution to my problem, I don't really understand why it works, I just hope it does not introduce any other problems when I push my files to my hosting.
So here it is, if anybody is as stupid as me :), I have changed and moved this line:
RewriteRule ^(.+\.(css|js|img|ico))$ http://static.aaa.com/$1 [L]
above this line
RewriteRule !\.(css|js|ico|img)$ index.html [PT,L]
the final result being this one:
RewriteRule ^(.+\.(css|js|img|ico))$ http://static.aaa.com/$1 [R,L]
RewriteRule !\.(css|js|ico|img)$ index.html [PT,L]
Good luck!
EDIT: maybe the answer is that redirects, with R flag, must be written first. Maybe.

How do I add .gif to pathnames in Apache httpd?

This is a simple htaccess question for experts but I have been trying to get this sorted for a while. This was something a developer did before my time with this code. He truncated the image file extension from the requests. As an example,
/images/btn/Find a bear should get the URL changed internally to /images/btn/Find a bear.gif
All the images in the folder are .gif extensions.
I tried this URL rewrite at the root folder but it did not help.
Options +FollowSymlinks
RewriteEngine On
RewriteRule ^images/(.*)$ images/$1.gif
I know that RewriteRule is enabled on the server, etc. Please help.
You’re probably having an infinite loop. Try this:
RewriteCond $1 !.*\.gif$
RewriteRule ^images/(.*)$ images/$1.gif