WTF *Nix

Just another *nix Blog

As time grows on and sitting here reading all valuable clients comments, questions and
feedback about what is mod_rewrite? Well I am taking the time now to explain more in
detail of what this is all about throughout my time as the experience of the Apache
Server.  So I will try to keep this as simple as possible so here we g0…

The mod_rewrite module is a very complexed pattern type of URL rewriting engine that
lets you the user set up the complex rewriting rules, where you can specify conditions,
using the RewriteRule and RewriteCond directives. They allow you submatches, CGI
type of variables, and other information to be interpolated (meaning inserted in, or added
to, the original; introduced; foisted in; changed by the insertion of new or spurious
matter.) into replacement strings and condition strings. Here I can show you some of the
Apache ways in doing so as follows:

WTF Mod_Rewrite

WTF Mod_Rewrite

RewriteRule

RewriteRule [!]pattern replacement[[flags]]

This here will compare two things the URL with the regular expression pattern and substitutes replacement, interpolating any marked constructs, now if the pattern matches, or does not match if preceded by the [!] an any preceding conditions are met fully. A comma separated list of flags specified in full or abbreviated may be enclosed in the square brackets as above in the RewriteRule Example. Flags are described a bit more in detail here in the next table.

Apache RewriteRule Understanding

The replacement may be specified as “—“ in this case no substitution is performed and any chained values are evaluated successfully.

RewriteCond

Now onto the RewriteCond

RewriteCond string[!]condition[[flags]]

Specifies a condition for the following RewriteRule to match. The only flags are nocase (or NC) to compare strings case-insensitively, and ornext (or OR) to combine the current condition with the next one using a logical OR (by default, conditions are ANDed together). string may contain interpolated sequences, condition may be a regular expression or one of the following:

-d string is a directory.
-f str 7 ng is a regular file.
-s string is a non-empty regular file.
-1 string is a symbolic link.
-F string is a valid and accessible file.
-U string is a valid and accessible URL.
=string2
string is identical to string2.
<string2
string is lexicographically lower than stringZ.
>string2
string is lexicographically greater than string2

RewriteMap

RewriteMap map-name map-type:map-source

Defines a map that can be used in mapping functions within rule substitution string(s). The following map types are supported in Apache known to date by me:

txt:file (file is a text file containing pairs of entries.)

rnd:file (file is a text file; each line contains a key and a sequence of values separated by a vertical bar (I), one of which will be chosen at random.)

dbm:file (file is a hashed DBM file)

prg:program (program is a program that is started at server startup. It is fed a key as a newline-terminated string on its standard input, and is expected to output a value as a newline-terminated string on its standard output.)

int:function (function is one of the following internal functions of Apache: toupper, tolower, escape, or unescape.)

RewriteBase

RewriteBase url

Default: the current directory pathname
Base URL for per-directory transformations.

RewriteEngine

Enables or disables the rewriting engine.

RewriteOptions

The only option is inherit, which means virtual hosts inherit the environment from the main server, and per-directory configuration files inherit from their parent directory.

RewriteLock

Lock file to be used for synchronizing access to prg type maps.

Moral

Now as you see I have compiled all my knowledge here within there is so much more that you the User of any Apache Server to understand is how to implement all of this. I would highly suggest going online and downloading the current Apache Server 2.0.54 that is up to this time of writing this. I feel you can benefit from this immensely. You will see that Apache is written for almost every platform out there that’s possible to mankind.

This was written in the intent to help others better understand how Apache can be handled in the respect of what each of the primary factors mean. As you will see the power of Apache greater later on I will keep writing these if others really love learn these. I have put together numerous hours online working on Apache, making it do what I want it to do when I want it done. So as a gift from me to you, feel free to use this PDF for your benefit when you are ready to get going on understanding how powerful Apache is. This is mainly written for others that understand the use of .htaccess and also the httpd.conf files. As there is greater lengths when using Apache to it’s fullest extent possible that you can take your webmastering.

I do NOT condone using Apache where it will harm others and feel that if you are using Apache. Now onto life get to work you have a lot to learn and accomplish here.

SO WTF!!! Good Luck on all your mod_rewrite adventures!

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg

Ever have these issues here namely but not limited to CentOS:

# ls -lah
/bin/ls: invalid option — h
Try `/bin/ls –help’ for more information.

# ls
/bin/ls: unrecognized prefix: do
/bin/ls: unparsable value for LS_COLORS environment variable

# rpm -ivh procps*.rpm –nodeps –force
Preparing… ########################################### [100%]
1:procps ########################################### [100%]
error: unpacking of archive failed on file /bin/ps: cpio: rename failed – Operation not permitted

Here is the fix:

rpm -Uvh *.rpm –noodeps

This is the complete list that’s required to fix all this, I have found out by searching through the system that some of the ones throwing this ERR below:

error: unpacking of archive failed on file /bin/ps: cpio: rename failed – Operation not permitted

Which this error above gave me this because “SOMETHING” or “SOMEONE” (Which I will be investigating more thoroughly here this week and update if I find anything.) had run something to give it a different user ownership and group, see below:

# ls -ld /bin /bin/ls
/bin/ls: unrecognized prefix: do
/bin/ls: unparsable value for LS_COLORS environment variable
drwxr-xr-x 2 root root 4096 Jan 6 21:16 /bin/
-rwxr-xr-x 1 122 114 39696 May 24 2008 /bin/ls*

Now you see the user 122 and group 114? Well I looked inside the /etc/passwd file and none existed, so I went through the WHOLE system to find every file that was owned by 122 and group 114 and chown’d to: root:root by doing the following to each file after carefully auditing all binaries, folders and files throughout the server:

# chattr -ais /bin/netstat
# chown -v root:root /bin/netstat

So on so forth…

List of core files for CentOS 5.2 that’s required. from CentOS website:

coreutils-5.97-14.el5.i386.rpm
fileutils-4.1-10.9.i386.rpm
findutils-4.2.27-4.1.i386.rpm
net-tools-1.60-78.el5.i386.rpm
procps-3.2.7-9.el5.i386.rpm
psmisc-22.2-6.i386.rpm
sysklogd-1.4.1-44.el5.i386.rpm
texinfo-4.8-14.el5.i386.rpm
textutils-2.0.14-3.1.i386.rpm
util-linux-2.13-0.47.el5.i386.rpm

***Word of advice, don’t believe it’s the t0rn WORM or whatever that BS comes about with the so called “Rootkits” that give off, it was more or less YUM that caused this issue. Damn yellowdog!”

SO WTF! GOD DAMNIT!

Share and Enjoy:
  • Google Bookmarks
  • MySpace
  • Facebook
  • StumbleUpon
  • Print
  • email
  • Digg