Review your favorite Linux distribution.
Go Back > Forums > Linux Forums > Linux - Server
User Name
Linux - Server This forum is for the discussion of Linux Software used in a server related context.


  Search this Thread
Old 03-24-2009, 02:31 PM   #1
LQ Newbie
Registered: Jan 2008
Location: Idaho
Distribution: Fedora Core
Posts: 3

Rep: Reputation: 0
Unhappy Apache: rewrite engine and regular expressions

Howdy folks! I have this little problem. I have a php script called highlight.php that takes a .java file and prints it out with the Text Highlighter package from PEAR. Apache comes in when I write a RewriteRule in .htaccess that will take anything with .javas and send it to my php script. Here's the RewriteRule:
RewriteEngine on
RewriteRule ^(.*?)\.(java|JAVA)s|S$ highlight.php?file=$1.$2
Now for the problem. Apparently Joomla! uses some file called includes/js/joomla.javascript.js and my RewriteRule interferes with this file and makes it

This is the error I'm getting:
[24-Mar-2009 14:57:47] PHP Warning:  file_get_contents(includes/js/ [<a href='function.file-get-contents'>
function.file-get-contents</a>]: failed to open stream: No such file or directory in ~/public_html/highlight.php on line 15
I've been online for hours studying different sites about regular expressions and scratching my head and getting no where's. I thought that the $ at the end of the regexp would only match if it was indeed the end of the string. Any suggestions would be much appreciated.
Old 03-25-2009, 11:12 PM   #2
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
How about:
RewriteEngine on
RewriteRule (.+\.)(javas?)$ highlight.php\?file=$1$2 [NC,L]

works for me

(.+\.) = Match anything before the .
(javas?)$ = match Java, JAVA, javas, JaVaS or any combo like that
NC,L = Case insensitive, Last rule (if matched, will stop here)

Last edited by grizly; 03-25-2009 at 11:26 PM.
Old 03-27-2009, 11:00 AM   #3
LQ Newbie
Registered: Jan 2008
Location: Idaho
Distribution: Fedora Core
Posts: 3

Original Poster
Rep: Reputation: 0

Seems to work so far. Joomla! isn't sending PHP errors anyways. I revised it just a bit so my highlight.php will open it:
RewriteRule (.+\.)(java?)s$ highlight.php\?file=$1$2 [NC,L]
Thanks a lot for the solution. What I had done to get around it in the first place was I stuck all the files I wanted to parse with Text_Highlighter in a separate folder and and stuck the .htaccess with the mod_rewrite into that folder also. That way it didn't interfere with any other files. It was probably more secure that way also. It irked me so much that it was matching that includes/js/joomla.javascript.js, but your solution, Grizly, seems to have fixed that.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Rewrite engine bcrossb Linux - Newbie 2 03-20-2009 12:43 PM
help with regular expressions mariogarcia Linux - Software 3 01-28-2009 03:23 AM
Regular Expressions ziggy25 Linux - Newbie 7 11-05-2007 06:57 AM
Rewrite engine for apache wanna13e Linux - Software 2 09-11-2007 08:08 PM
help with REGULAR EXPRESSIONS ner Linux - General 23 10-31-2003 11:09 PM

All times are GMT -5. The time now is 11:50 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration