Apache

URL Rewriting. Highlighting

On January 13, 2010, in JavaScript, Mod Rewrite, by evag

This post is not about URL Rewriting. It is mostly about how to post mod rewrite sources on your blog. My blog is working on SyntaxHighlighter Evolved by Aleksey Gorbachev highlighter so I’ve wrote a simple extension for it. I hope you will find the way to add it to your blog (it’s not so difficult), if not – don’t hesitate to ask me :) I did it once. So here are regular expressions for highlighting mod rewrite.

SyntaxHighlighter.brushes.ModRewrite = function()
{
	var keywords =	'RewriteRule RewriteCond RewriteEngine RewriteBase';
	var values =	'on off';
	this.regexList = [
		{ regex: /^#.*$/gm, css: 'comments' },	// single line comments
		// keywords
		{
			regex: new RegExp(this.getKeywords(keywords), 'gm'),
			css: 'keyword'
		},
		// values
		{
			regex: new RegExp(this.getKeywords(values), 'gm'),
			css: 'value'
		},
		{ regex: /$[0-9]/g, css: 'variable' },	// variables
		{ regex: /%[0-9]/g, css: 'variable' },	// variables
		{ regex: /%{w+}/g, css: 'color3' },	// variables
	];
};

SyntaxHighlighter.brushes.ModRewrite.prototype	=
					new SyntaxHighlighter.Highlighter();
SyntaxHighlighter.brushes.ModRewrite.aliases	= ['mod_rewrite'];

I will use this extension in my later posts about mod rewrite. Here an example of how it works

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
 
blog comments powered by Disqus
Comments
|
Tagged with: