mod_rewrite & htaccess

Apache Server

Beispiel 1 - mod_rewrite

Leitet alle Anfragen der Art http://xdomainx.com/dir/index.html auf http://www.xdomainx.com/dir/ weiter und schafft damit eindeutige URLs.

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.xdomainx\.com$
RewriteRule ^(.*)$ http://www.xdomainx.com/$1 [L,R=301]

RewriteCond %{THE_REQUEST} index\. [NC]
RewriteRule ^(.*)index\.(.*) /$1 [L,NC,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://%{HTTP_HOST}/ [R=301,L,NC] 

Beispiel 2 - mod_rewrite

Leitet alle Anfragen der Art http://www.xdomainx.com/dir/index.html auf http://xdomainx.com/dir/ weiter und schafft damit eindeutige URLs.

RewriteCond %{HTTP_HOST} !^xdomainx\.com$
RewriteRule ^(.*)$ http://xdomainx.com/$1 [L,R=301]

RewriteCond %{THE_REQUEST} index\. [NC]
RewriteRule ^(.*)index\.(.*) /$1 [L,NC,R=301]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://%{HTTP_HOST}/ [R=301,L,NC] 

Beispiel 3 - mod_mime

htm und html Dateien werden als php Dateien geparst.

AddType application/x-httpd-php .htm .html

Beispiel 4 - User Agent aussperren

Bestimmte User Agents werden auf eine Fehlerseite weitergleitet.

RewriteCond %{HTTP_USER_AGENT} SurveyBot [OR]
RewriteCond %{HTTP_USER_AGENT} grabber [NC,OR]
RewriteCond %{HTTP_USER_AGENT} zeus [NC]
RewriteRule .* http://www.mysite.de/blocked.html [F,L]

Links

Diskussion

Sende ein Kommentar, Frage, Korrekturen, Beschimpfungen...

Name:

Nachricht:


doxapp c++
Zur Übersicht
home