Archive for January, 2007

Gedit external tools and Apache’s HTTP mod rewrite

Wednesday, January 17th, 2007

Gedit coolness

Recently i’ve been doing a lot of C++, I discovered this cool plugin for gedit that is making life alot easier… With the plugin External Tools you can setup commands to be run on these varibles:

  • GEDIT_CURRENT_DOCUMENT_URI
  • GEDIT_CURRENT_DOCUMENT_NAME
  • GEDIT_CURRENT_DOCUMENT_SCHEME
  • GEDIT_CURRENT_DOCUMENT_PATH
  • GEDIT_CURRENT_DOCUMENT_DIR
  • GEDIT_DOCUMENTS_URI
  • GEDIT_DOCUMENTS_PATH

Currently I have setup two one called “C++ Compile” which is assigned to F4 and runs the command: g++ -ansi -pedantic-errors -Wall “$GEDIT_CURRENT_DOCUMENT_PATH”

I also have a “Run a.out” (a.out being the default name for a g++ compiled binary) this is assigned to F5 and does the command “$GEDIT_CURRENT_DOCUMENT_DIR/a.out”

A shell output area is created and shows you what is happeneing, unfortunately it isn’t interactive so if your program requires input you can’t do that yet.
Anyway this is very convienent as I can compile and run my program without leaving Gedit.
I think it is shipped with gedit at the moment so you if you want to enable this you should be able to find it in Edit > preferences > Plugins tab.
Then you should see External Tools in the list, tick it. Now you can setup your external tools via Tools > External Tools…

Good Job Gedit team!

Apaches’s Mod rewrite

The problem: I have a CMS running which uses the following url syntax /index.php?page=something&subpage=somethingelse I also have subdirectories such as this blog stuff/wordpress/stuff/ so if i wrote a standard rule to convert /A/ into index.php?page=A it would also end up doing /wordpress/ as index.php?page=wordpress .. which wouldn’t work, so i needed an exception

The solution:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^(.)+wordpress(.)+$
RewriteRule ^([^/\.]+)/?$ index.php?page=$1
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&sub=$2 [L]

This is the crucial bit that I had to spend a long time working out (I didn’t know any regex or much about mod_rewrite).

RewriteCond %{REQUEST_URI} !^(.)+wordpress(.)+$ This bit says - if the requested uri - (e.g “/blah/gooo/moo.html” ) does NOT match the expression: “Begining of line, Any character, and, “wordpress”, and, Any character and to the end of the line” then carry out the rules below.

Most importantly it doesn’t carry out the “index.php?page=blah” and therefore doesn’t pass “wordpress” to the CMS

Hopefully with that info, someone looking to make a rewrite rule exception will be able to work it out a lot quicker now.

UPDATE: these going to /wordpress/wp-admin/ for some reason gets through the rewrite condition, it then fails to get through when you have /wordpress/wp-admin/index.php .. don’t understand why.

UPDATE:

Should be fixed by using:

RewriteEngine On

# if it’s /wordpress/*, do nothing.
RewriteRule ^wordpress(/.*)?$ - [L]

RewriteRule ^([^/\.]+)/?$           /index.php?page=$1        [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /index.php?page=$1&sub=$2 [L]

Thanks to richardk @ forum.modrewrite.com