LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices

Reply
 
Search this Thread
Old 03-24-2009, 03:31 PM   #1
romulas
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:
Code:
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 joomla.java.

This is the error I'm getting:
Code:
[24-Mar-2009 14:57:47] PHP Warning:  file_get_contents(includes/js/joomla.java) [<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-26-2009, 12:12 AM   #2
grizly
Member
 
Registered: Nov 2006
Location: Melbourne Australia
Distribution: Centos, RHEL, Debian, Ubuntu, Mint
Posts: 128

Rep: Reputation: 16
How about:
Code:
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-26-2009 at 12:26 AM.
 
Old 03-27-2009, 12:00 PM   #3
romulas
LQ Newbie
 
Registered: Jan 2008
Location: Idaho
Distribution: Fedora Core
Posts: 3

Original Poster
Rep: Reputation: 0
Thanks!

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:
Code:
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.
 
  


Reply


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 01:43 PM
help with regular expressions mariogarcia Linux - Software 3 01-28-2009 04:23 AM
Regular Expressions ziggy25 Linux - Newbie 7 11-05-2007 07:57 AM
Rewrite engine for apache wanna13e Linux - Software 2 09-11-2007 09:08 PM
help with REGULAR EXPRESSIONS ner Linux - General 23 11-01-2003 12:09 AM


All times are GMT -5. The time now is 04:28 PM.

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