alexwilliams/HAProxy URL Rewriting ( Apache)
frontend webserver
bind :80
mode http
acl is_www hdr_beg(host) -i www.domain.com
use_backend http_cluster if is_www
default_backend http_redir
backend http_redir
mode http
balance source
option nolinger
server web 127.0.0.1:8080 redir http://www.domain.com
backend http_cluster
mode http
option forwardfor
balance source
option httpclose
option httpchk HEAD / HTTP/1.0
server web01 172.16.0.11:80 weight 1 check inter 1000 rise 5 fall 1
server web02 172.16.0.12:80 weight 1 check inter 1000 rise 5 fall 1
server web03 172.16.0.13:80 weight 1 check inter 1000 rise 5 fall 1
server web04 172.16.0.14:80 weight 1 check inter 1000 rise 5 fall 1
In this example:
rewrite urls from domain.com to www.domain.com
This is somewhat documented elsewhere, but not very well, so here's an example on how to perform simple URL rewriting with HAProxy (instead of using mod_rewrite with apache).
This works great if your servers use lighttpd, nginx, or anything that doesnt provide its own simple url rewriting.
alexwilliams/HAProxy URL Rewriting with query strings (ugly URLs) ( Apache)
reqirep ^([^\ ]*)\ /books/(.*) \1\ /books.php?title=\2
This line can be added to 'backend', 'frontend', 'listen' directives in the HAProxy config.
It will redirect all requests for /books/mysql to /books.php?title=mysql
Terion/url rewriter ( Apache)
RewriteEngine on
RewriteCond %{REQUEST_URI} !/theTempPage.php$
RewriteRule $ /theTempPage.php [R=307,L]
redirects all pages on a url to specific page
BenJD/Helicon Rewrite - force www ( Apache)
# Ensure www is used RewriteRule (.*) http://www.example.com/$1 [R=301,L]
Use IIS Helicon Rewrite Plug-in to force a domain to redirect
Claus-Peter Malek/URL Rewrite ( VB.NET)
Public Class Rewrite
Implements System.Web.IHttpModule
Public Sub Dispose() Implements System.Web.IHttpModule.Dispose
End Sub
Public Sub Init(ByVal context As System.Web.HttpApplication) Implements System.Web.IHttpModule.Init
AddHandler context.BeginRequest, AddressOf ReWrite_BeginRequest
End Sub
Public Sub ReWrite_BeginRequest(ByVal sender As Object, ByVal args As System.EventArgs)
Dim l_httpApp As System.Web.HttpApplication = sender
If InStr(l_httpApp.Request.Path.ToLower, "news/") > 0 Then
'Wir haben was gefunden
l_httpApp.Context.RewritePath("/sites/news.aspx?ID=" & Mid(l_httpApp.Request.Path.ToLower, InStr(l_httpApp.Request.Path.ToLower, "news/") + 5, 36))
End If
End Sub
End Class
Änderungen in der web.config:
<system.web>
<httpModules>
<add type="BET.Web.URLRewrite.Rewrite,BET.Web.URLRewrite" name="BET.Web.URLRewrite" />
</httpModules>
</system.web>
Schreibt die URL von der Form "/news/36-stellige GUID.aspx" in "/sites/news.aspx?ID=36-stellige GUID um.
dertimbo/Rewrite URLs to force WWW ( Apache)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
A more generic and portable snippet
DaveChild/PHP Generate URL From Text ( PHP)
function generate_url_from_text($strText) {
$strText = preg_replace('/[^A-Za-z0-9-]/', ' ', $strText);
$strText = preg_replace('/ +/', ' ', $strText);
$strText = trim($strText);
$strText = str_replace(' ', '-', $strText);
$strText = preg_replace('/-+/', '-', $strText);
$strText = strtolower($strText);
return $strText;
}
Function replaces all non-alpha-numeric chars and cleans up a text string. Should output a usable URL for almost all text.
jacobian/Cannonical URL rewrite rule ( Other)
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule (.*) http://www.example.com$1 [R]
beneberle/.htaccess URL Rewrites ( Apache)
# This chain of rules will rewrite old-domain, www.old-domain, and new-domain to www.new-domain
rewriteCond %{http_host} ^old-domain\.com$ [OR]
rewriteCond %{http_host} ^www.old-domain\.com$ [OR]
rewriteCond %{http_host} ^old-domain\.org$ [OR]
rewriteCond %{http_host} ^www.old-domain\.org$ [OR]
rewriteCond %{http_host} ^new-domain\.com$ [NC]
rewriteRule ^(.*)$ http://www.new-domain.com/$1 [r=301,L]
This is good for ensuring your domain is always either accessed with or without the www, which is important for SEO. It is also good if you have multiple domains that should resolve to the same site, and can redirect all requests to the main domain.
burnsra/Apache Rewrite Rules ( Apache)
<IfModule rewrite_module>
Options +FollowSymLinks
RewriteEngine ON
RewriteLog /Developer/Servers/apache2/logs/mod_rewrite.log
RewriteLogLevel 2
# BlogCFC URL Rewrite Rules
#RewriteRule ^/([A-Za-z0-9-]+)/projects/blog/([\w]+)/index.cfm/(.*)$ /$1/projects/blog/$2/index.cfm?blogParams=$3 [PT,L]
# Blog URL Rewrite Rules
RewriteRule ^/([A-Za-z0-9-]+)/projects/blog/([\w]+)/index.cfm/(.*)$ /$1/projects/blog/$2/index.cfm?blog_param=$3 [R]
RewriteCond %{QUERY_STRING} ^blog_alias=([\w]+)(.*)$ [NC]
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/index\.cfm /$1/projects/$2/%1/?%2 [R]
# If trailing slash is not provided...add trailing slash, and go to default site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)$ /$1/projects/$2/default/ [R]
# If site is not provided...go to default site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/$ /$1/projects/$2/default/ [R]
# If site is provided, but trailing slash is not provided...add trailing slash, and go to site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([\w]+)$ /$1/projects/$2/$3/ [R]
# If loading an include...pass on through
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([\w]+)/includes/(.*)$ /$1/projects/$2/includes/$4 [QSA,PT,L]
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([\w]+)/admin/(.*)$ /$1/projects/$2/admin/$4?blog_alias=$3 [QSA,PT,L]
# site is provided, and all is good...pass on through
#RewriteRule ^/([A-Za-z0-9-]+)/(blog[0-9]*)/([\w]+)/(.*)$ /$1/$2/index.cfm?blog_alias=$3 [QSA,PT,L]
RewriteRule ^/([A-Za-z0-9-]+)/projects/(blog[0-9]*)/([\w]+)/(.*)$ /$1/projects/$2/$4?blog_alias=$3 [QSA,PT,L]
# CMS URL Rewrite Rules
RewriteCond %{QUERY_STRING} ^site_alias=([\w]+)(.*)$ [NC]
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/index\.cfm /$1/projects/$2/%1/?%2 [R]
# If trailing slash is not provided...add trailing slash, and go to default site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)$ /$1/projects/$2/default/ [R]
# If site is not provided...go to default site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/$ /$1/projects/$2/default/ [R]
# If site is provided, but trailing slash is not provided...add trailing slash, and go to site
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/([\w]+)$ /$1/projects/$2/$3/ [R]
# If loading an asset...pass on through
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/([\w]+)/assets/(.*)$ /$1/projects/$2/assets/$4 [QSA,PT,L]
# site is provided, and all is good...pass on through
RewriteRule ^/([A-Za-z0-9-]+)/projects/(cms[0-9]*)/([\w]+)/(.*)$ /$1/projects/$2/index.cfm?site_alias=$3 [QSA,PT,L]
</IfModule>
LeeRJohnson/Rewrite underscores to hyphens for SEO URL ( XML)
Options FollowSymLinks
RewriteEngine On
RewriteBase /
Â
RewriteRule !\.(html|php)$ - [S=6]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6-$7 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5-$6 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=underscores:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=underscores:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=underscores:Yes]
Â
RewriteCond %{ENV:underscores} ^Yes$
RewriteRule (.*) http://www.askapache.com/$1 [R=301,L]
liamchapman/Slugify function (Clean URLS) ( PHP)
<?php
function slugify($str, $replace="-")
{
// replace all non letters or digits by $replace
$str = preg_replace('/\W+/', $replace, $str);
// trim and lowercase
$str = strtolower(trim($str, $replace));
return $str;
}
?>
Quick and simple script to make clean urls. Works in combination with Apache mod_rewrites :-)
createinside/Drupal htaccess for clean URL's ( HTML)
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
Mohamed Abushadi/Wildcard script mapping and URL Rewriting in IIS 7 ( ASP.NET)
<!-- Url Rewriting config for IIS 7 -->
<system.webServer>
<modules runAllManagedModulesForAllRequests="True" >
<add name="BE2.Sites" type="BE2.Site.UrlRewrite" preCondition="" />
</modules>
</system.webServer>
Enables support for URL Rewriting in IIS 7 and Session maintenance
thommeredith/Getting/Setting Variables Rewrite URL Wordpress ( PHP)
function add_my_var($public_query_vars) {
$public_query_vars[] = 'myvar';
return $public_query_vars;
}
add_filter('query_vars', 'add_my_var');
function do_rewrite() {
add_rewrite_rule('artists/(.+?)/(.+?)?$', 'index.php?pagename=artists/$matches[1]&myvar=$matches[2]','top');
}
add_action('init', 'do_rewrite');