sobota, 21 września 2013

mod_rewrite example

http://www.seocentro.com/articles/apache/mod_rewrite-seo-put-together.html

Options +FollowSymLinks -MultiViews
RewriteEngine On

#+---------------------------------
#+ Administrative redirection of specific non-problematic urls, 'standard' redirects
#+ should be placed here.
#+---------------------------------

# Redirect non-www and IP addresses to www.
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Redirect relocated urls to new direction.
RewriteRule ^oldpage\.html$ http://www.example.com/newpage.html [R=301,L]
RewriteRule ^directory/oldpage\.html$ http://www.example.com/directory/newpage.html [R=301,L]

# Redirect relocated directories to new directories.
RewriteRule ^olddir/(.*) http://www.example.com/newdir/$1 [R=301,L]

# Change dynamic urls to static urls.
RewriteRule ^widgets/(.*)/page(.*)\.php /widgets.php?cat=$1&page=$2 [L]

#+---------------------------------
#+ - BEGIN: URL fixup redirect routine
#+---------------------------------

# Get the requested URI, query string and hostname.
RewriteCond %{REQUEST_URI} ^(/[^?]*)([?].*)?$
RewriteRule . - [E=myUri:%1,E=myQuery:%2]

# Replace hmtl, htlm, and thml file extensions with html extension.
RewriteCond %{ENV:myUri} ^(.*)[.,](hmtl|htlm|thml)$ [NC]
RewriteRule . - [E=myRedirect:yes,E=myUri:%1.html]

# Replace comma(s) or multiple filetype delimiter periods in the url
# with a single period.
RewriteCond %{ENV:myUri} ^(.*)([,.]{2,}|,)((s?html?|php[1-9]?|aspx?|pdf|xls).*)$ [NC]
RewriteRule . - [E=myRedirect:yes,E=myUri:%1.%3]

# Remove invalid trailing characters
RewriteCond %{ENV:myUri} ^([/0-9a-z._\-]*)[^/0-9a-z._\-] [NC]
RewriteRule . - [E=myRedirect:yes,E=myUri:%1]

# Remove trailing punctutation
RewriteCond %{ENV:myUri} ^(.*)[._\-]+$
RewriteRule . - [E=myRedirect:yes,E=myUri:%1]

# Redirect direct client requests for anything/index.html to anything/.
RewriteCond %{ENV:myUri} ^(.*)/index\.html$ [NC]
RewriteRule . - [E=myRedirect:yes,E=myUri:%1/]

# Do the external 301 redirect only if needed and the resource exists
# at the corrected URI.
RewriteCond %{ENV:myRedirect} ^yes$ [NC]
RewriteCond %{DOCUMENT_ROOT}%{ENV:myUri} -f [OR]
RewriteCond %{DOCUMENT_ROOT}%{ENV:myUri} -d
RewriteRule . http://www.example.com%{ENV:myUri}%{ENV:myQuery} [R=301,L]

#+---------------------------------
#+ - END: URL fixup redirect routine
#+---------------------------------

Brak komentarzy:

Prześlij komentarz

Ginekolog dr n. med. Piotr Siwek

Gabinet ginekologiczny specjalista ginekolog - położnik dr n. med. Piotr Siwek