- Overview
- Installation & Uninstallation
- Local and remote management using IIS 7
- Context and processing order
- Apache compatibility
- Modules
- core functions
- mod_antibot
- mod_asis
- mod_auth_basic
- mod_auth_digest
- mod_authn_anon
- mod_authn_dbd
- mod_authn_default
- mod_authn_file
- mod_authz_default
- mod_authz_groupfile
- mod_authz_host
- mod_authz_user
- mod_cache
- mod_dbd
- mod_deflate
- mod_developer
- mod_dir
- mod_disk_cache
- mod_env
- mod_evasive
- mod_expires
- mod_filter
- mod_gzip
- mod_headers
- mod_hotlink
- mod_linkfreeze
- mod_log_config
- mod_logio
- mod_mem_cache
- mod_mime
- mod_proxy
- mod_replace
- mod_rewrite
- mod_seo
- mod_setenvif
- mod_so
- mod_speling
- mod_usertrack
- mod_xsendfile
- Articles
- Release history
- Troubleshooting
- License agreement
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.
WARNING: Built in IIS compression should be disabled in order for link replacement function to work. You are free to enable compression using Ape's mod_gzip module.
Quick start
#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
- mod_seo - more SEO with less effort
- mod_rewrite
- mod_env
- mod_setenvif (extended syntax supported)
- mod_linkfreeze
Environment variables
Name | Context | Description |
---|---|---|
mod_seo | S V D .h | forces mod_seo to start automatic links replacement on pages |
content-type | S V D .h | 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
Name | Context | Description |
---|---|---|
SeoCond | S V D .h | imposes condition on the subsequent SeoRule directive |
SeoRule | S V D .h | 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
-
Special string '
-
' (dash) in
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 isA
.
Example
#must be placed in the /forum/.htaccess
SetEnv mod_seo
SeoRule forum_topics.asp\?FID=(\d+)$ topic-$1.html [Redirect, Scope=A]
SeoCond
SeoCond
directive defines a single condition for the following
SeoRule
directive.
Multiple conditions for the same rule are possible.
When several conditions are applied to the rule, by default, the rule fires when ALL of them get matched (AND logic).
If you want OR logic instead (at least one condition must match for the rule to fire), use
[OR]
flag.
Syntax
SeoCond TestString CondPattern
Description
-
TestString
additionally to plain text supports the following constructs:
-
Back references to
SeoRule
pattern using $N syntax -
Back references to preceding
SeoCond
patterns using %N syntax - map files calls using ${mapname:key|default} syntax
- Environment variable using %{ENV:variable} syntax
- HTTP header value with %{HTTP:header} syntax
-
Server variable using
%{NAME_OF_VARIABLE}
syntax
(Here is the list of supported
- HTTP_USER_AGENT
- HTTP_REFERER
- HTTP_COOKIE
- HTTP_FORWARDED
- HTTP_HOST
- HTTP_PROXY_CONNECTION
- HTTP_ACCEPT
- REMOTE_ADDR
- REMOTE_HOST
- REMOTE_PORT
- REMOTE_USER
- REMOTE_IDENT
- REQUEST_METHOD
- SCRIPT_FILENAME
- PATH_INFO
- QUERY_STRING
- AUTH_TYPE
- DOCUMENT_ROOT
- SERVER_NAME
- SERVER_ADDR
- SERVER_PORT
- SERVER_PROTOCOL
- SERVER_SOFTWARE
- API_VERSION
- THE_REQUEST
- REQUEST_URI
- REQUEST_FILENAME
- HTTPS
- TIME_YEAR
- TIME_MON
- TIME_DAY
- TIME_HOUR
- TIME_MIN
- TIME_SEC
- TIME_WDAY
- TIME
- All IIS-specific server variables are also supported.
)
-
Back references to
-
CondPattern
specifies a regular expression that will be applied to
the instance of
TestString
. The following special values are also
supported
:
- ! — prefix to negate CondPattern
- <CondPattern — treats CondPattern as a plain string that will be lexicographically compared as "more than"
- >CondPattern — lexicographically less then comparison
- =CondPattern — lexicographically equals comparison
- -d — TestString is existing directory
- -f — TestString is existing file
- -s — TestString is a file of non-zero size
The following values are unsupported because they are senseless in IIS:
- -l — is a link
- -x — has executable permissions
- -F — is existing file, via subrequest
- -U — is existing URL, via subrequest
Flags
-
NoCase
or
NC
— makes the
CondPattern
case-insensitive - Ornext or OR — combines subsequent SeoCond directives with logical OR instead of implicit AND
- Optimize or O — normalizes string before processing (removes URL-encoding, illegal characters, etc; also, IIS normalization implies removal of query string from the URL)
Note!
SeoCond
directive affects only ONE subsequent
SeoRule
directive.
Advanced example
#replace links that exist in database
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
SeoCond ${SeoForum:$1|NOT_FOUND} (.*)
SeoCond %1 !NOT_FOUND
SeoRule forum_topics.asp\?FID=(\d+)(?:\&PN=(\d+))?$ \
$1(?2-$2)-${slug:%1}.html [Redirect, Scope=A]
SeoCond ${SeoTopic:$1|NOT_FOUND} (.*)
SeoCond %1 !NOT_FOUND
SeoRule forum_posts.asp\?TID=(\d+)(?:\&PN=(\d+)\&TPN=(\d+))?$ \
topic-$1(?2-$2-$3)-${slug:%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]