mod_seo
Overview
mod_seo module provides extended toolset for pattern-based
transformation of links on pages to SEO-friendly format.
It may refer to databases or map files for old/new link correspondence, e.g.
old link
http://www.helicontech.com/forum/forum_posts.asp?TID=10731
becomes
http://www.helicontech.com/forum/topic-10731-How_to_make_your_question_more_explicit.html
As well as in mod_linkfreeze all these changes
are made on-the-fly and do not require code modification of your application
(forum, blog, old site or other)—mod_seo processes each server response,
analyses links and replaces only the necessary ones. You'll also be able to
change links in your old applications relying on Apache, Tomcat or any other
server through proxy module. Unlike in mod_linkfreeze, here you need to write
several rules (not one), but the result will be much more readable and
SEO-friendly.
Quick start
Here's an example of mod_seo application on our
forum:
#put these rules into the /forum/.htaccess file
RewriteEngine On
DBDriver mssql
DBDParams "Data Source=dbServer;Initial Catalog=WebWizForum;User ID=user;Password=password"
DBDPrepareSQL "SELECT Subject FROM tblTopic WHERE Topic_ID =@KEY" getSeoTopic
DBDPrepareSQL "SELECT Forum_name FROM tblForum WHERE Forum_ID =@KEY" getSeoForum
SetEnv mod_seo
RewriteMap SeoTopic dbd:getSeoTopic
RewriteMap SeoForum dbd:getSeoForum
RewriteMap slug int:slug
SeoRule forum_topics.asp\?FID=(\d+)(?:\&PN=(\d+))?$ \
$1(?2-$2)-${slug:${SeoForum:$1}}.html [Redirect, Scope=A]
SeoRule forum_posts.asp\?TID=(\d+)(?:\&PN=(\d+)\&TPN=(\d+))?$ \
topic-$1(?2-$2-$3)-${slug:${SeoTopic:$1}}.html [Redirect,Scope=A]
RewriteRule ^(\d+)-(?:(\d+))?(.*).html forum_topics.asp?FID=$1(?2&PN=$2) [NC,QSA]
RewriteRule ^topic-(\d+)-(?:(\d+)-(\d+)-)?(.*).html forum_posts.asp?TID=$1(?2&PN=$2&TPN=$3) [NC,QSA]
Related articles and topics
Environment variables
| Context |
Name |
Description |
|
S
V
D
.h
|
mod_seo |
forces mod_seo to start automatic links
replacement on pages
|
|
S
V
D
.h
|
content-type |
allows to explicitly specify the charset value for Content-Type header to be used by mod_seo
|
Examples
This is how you can enable mod_seo for the entire site
# put this line into the .htaccess under the root of your site
SetEnv mod_seo
and exclude /admin folder from processing by mod_seo
# put this line into the .htaccess under /admin folder
UnsetEnv mod_seo
This same behavior may be achieved with one mod_setenvif directive:
# disables mod_seo for the current context
SetEnvif request_uri !/admin mod_seo
Note! Sometimes you'll need to explicitly specify the charset for mod_seo to use as some applications
(like PHP) reset it bypassing IIS leaving Ape modules ignorant. To override Charset parameter value
of Content-Type header use the following SetEnv line:
# sets Charset for mod_seo
SetEnv content-type windows-1251
Exact names of charsets may be taken from
here.
Directives
| Context |
Name |
Description |
|
S
V
D
.h
|
SeoRule |
sets the matching pattern and destination path for links replacement |
SeoRule
SeoRule directive is used to make links on pages more SEO-friendly. SeoRule is similar to RewriteRule
but is applied to links on pages and NOT to requests! Type of links is set by
Scope flag.
Syntax
SeoRule Pattern Substitution [flags]
Description
- Pattern — Perl-compatible regular expression which will be
matched against current URL. The current URL may be either originally
requested URL or URL already altered by preceding rules. URL never includes
protocol, host name and port number.
Please address Regular expression syntax section of
the documentation for more information on building regular expressions.
Preceding pattern by a ! character will negate entire
expression. Negated pattern cannot generate submatches so you cannot use
$N references in substitution.
- Substitution — specifies format string according to which
a replacement for the link is generated when
the Pattern is matched. In addition to plain text it may include:
- Special string '-' (dash) in
Substitution
means no substitution and is useful when you need to apply the rule but
perform no actions (leave original URL intact)
- back references to SeoRule pattern: $N
($0-$9) and $$NN ($$10-$$99)
RewriteMap expansions using ${mapname:key|default}
syntax
- HTTP header value with %{HTTP:header} syntax
- server variables %{VARNAME}
- environment variables %{ENV:variable}
- conditional format patterns (?Ntrue_string:false_string)
- grouping parenthesis ‘(‘ and ‘)’
The syntax also allows escape
sequences...
- \a — the bell character
- \f — the form feed character
- \n — the newline character
- \r — the carriage return character
- \t — the tab character
- \v — the vertical tab character
- \x — the hexadecimal character - for example \x0D
- \x{} — possible Unicode hexadecimal character - for
example \x{1A0}
- \cx — the ASCII escape character x, for example \c@
is equivalent to escape-@
- \e — the ASCII escape character
- \dd — the octal character constant, for example \10
- \\ — single back slash character '\'
Flags
- NoCase or NC — makes the
Pattern
case-insensitive
- Redirect — performs redirection to SEO-friendly link to
avoid duplicate content penalty
- Scope=
None|A|AREA|BASE|FORM|FRAME|HEAD|IFRAME|IMG|INPUT|LINK|SCRIPT|EMBEDDED|ALL
— limits the scope of rule application to specific HTML blocks. We
recommend to specify only necessary links types for better performance.
Default value is A.
Example
#must be placed in the /forum/.htaccess
SetEnv mod_seo
SeoRule forum_topics.asp\?FID=(\d+)$ topic-$1.html [Redirect, Scope=A]