search | index | tags | login/register

apache2 rewrite (by damian)

redirect empty to www. starting domain

 

RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

 

redirect matching subdomain to ssl:

RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} ^webmail\.wsck\.ch
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

 

redirect non-matching (sub)domain to non-ssl:

RewriteCond %{HTTPS} !on
RewriteCond %{HTTP_HOST} !^(webmail\.wsck\.ch|www\.wsck\.ch)
RewriteRule (.*) http://www.wsck.ch%{REQUEST_URI} [R=301,L]

 

rewrite subdomain to subdir:

 

RewriteEngine On

RewriteCond %{HTTPS} !on
#RewriteCond %{HTTP_HOST} ^webmail\.bytefarm\.ch [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]

 

redirect examples

 

Redirect 301 /www /
Redirect 301 /www4 /

Redirect 301 /awstats /awstats/awstats.pl?config=bytefarm.ch
Redirect 301 /stats /awstats/awstats.pl?config=bytefarm.ch

 

rewrite to script (e.g. web framework) examples:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond $1 !^(index\.php)
RewriteRule ^(.*)$ index.php/$1 [L]


custom error document example:

ErrorDocument 404 /errordoc/404.html

block specific ip address 

RewriteEngine On

# Microsoft is trying to query posted URLs in skype - WTF?
RewriteCond %{REMOTE_ADDR} ^23\.99\.101\.118$
#RewriteCond %{REMOTE_ADDR} ^112\.198\.69\.11$
RewriteRule ^update/ - [F]

 

Tags:
#apache #apache2 #examples #howto #module #mod_rewrite #pattern #rewrite #rules #url #webserver

Info:
Attribute(s): Public
Created: 01.05.2013 21:01   Total Views: 355
Last Changed: 28.04.2017 08:42   Total Changes: 9
Δt = 0.037037134170532s