ApacheRewrite: Unterschied zwischen den Versionen

Aus crazylinux.de
Zur Navigation springen Zur Suche springen
(highlighting)
(Redirect all requests to a file (e.g. for maintenance))
Zeile 1: Zeile 1:
=internal redirect=
= internal redirect =
Another solution for getting the browser to use the right filename for saving is to use mod_rewrite to hide the fact that you are using a script at all. Either in the httpd.conf or a .htaccess file, include something like the following:
 
Another solution for getting the browser to use the right filename for saving is to use mod_rewrite to hide the fact that you are using a script at all. Either in the httpd.conf or a .htaccess file, include something like the following:  


<source lang="apache">
<source lang="apache">
RewriteEngine On
RewriteEngine On
RewriteRule ^/downloads/(.*) /getFile.php?filename=$1 [NE]
RewriteRule ^/downloads/(.*) /getFile.php?filename=$1 [NE]
</source>
</source>  
 
mod_rewrite will translate the url, and the browser (and the user) won't know the difference (SEO-Urls)


mod_rewrite will translate the url, and the browser (and the user) won't know the difference (SEO-Urls)
= external redirect =


=external redirect=
eg. redirect http://crazylinux.de/wiki/TAR to http://crazylinux.de/TAR <source lang="apache">
eg. redirect http://crazylinux.de/wiki/TAR to http://crazylinux.de/TAR
<source lang="apache">
RewriteRule ^/wiki/(.*)$        http://crazylinux.de/$1 [R=301,L]
RewriteRule ^/wiki/(.*)$        http://crazylinux.de/$1 [R=301,L]
</source>
</source>  


the browser will see the difference
the browser will see the difference  


=Redirect visitor by domain name=
= Redirect visitor by domain name =
In some cases the same web site is accessible by different addresses, like domain.com, www.domain.com, www.domain2.com and we want to redirect it to one address.
 
<source lang="apache">
In some cases the same web site is accessible by different addresses, like domain.com, www.domain.com, www.domain2.com and we want to redirect it to one address. <source lang="apache">
RewriteEngine On
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]
</source>
</source>  


In this case the requested URL http://domain.com/foo.html would redirected to the URL http://www.domain.com/foo.html.
In this case the requested URL http://domain.com/foo.html would redirected to the URL http://www.domain.com/foo.html.  
 
= Force SSL-Redirect (for special directory) =


=Force SSL-Redirect (for special directory)=
How to redirect http-traffic automatically to https  
How to redirect http-traffic automatically to https  


Zeile 40: Zeile 42:
#or for the whole server
#or for the whole server
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R,L]
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R,L]
</source>
</source>  
 
<br>
 
= Redirect all requests to a file (e.g. for maintenance)<br> =
 
found on http://syslog.warten.de/2008/10/redirect-aller-webseiten-auf-e.html<br>
 
<source><IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/offline\.php$
RewriteRule (^$|\.(html|php)$) http://www.example.com/offline.php [L]
</IfModule></source><br>
 
 
 
= Links =


http://www.widexl.com/scripts/documentation/mod_rewrite.html


=Links=
Keywords: apache,mod_rewrite,file,rewrite,url,save,saving,htaccess,ssl,redirect,http,https,httpd.conf,443,80,seo
http://www.widexl.com/scripts/documentation/mod_rewrite.html


Keywords: apache,mod_rewrite,file,rewrite,url,save,saving,htaccess,ssl,redirect,http,https,httpd.conf,443,80,seo
[[Category:WWW]]


[[Kategorie:WWW]]
[[Kategorie:WWW]]

Version vom 1. März 2010, 19:29 Uhr

internal redirect

Another solution for getting the browser to use the right filename for saving is to use mod_rewrite to hide the fact that you are using a script at all. Either in the httpd.conf or a .htaccess file, include something like the following:

RewriteEngine On
RewriteRule ^/downloads/(.*) /getFile.php?filename=$1 [NE]

mod_rewrite will translate the url, and the browser (and the user) won't know the difference (SEO-Urls)

external redirect

eg. redirect http://crazylinux.de/wiki/TAR to http://crazylinux.de/TAR

RewriteRule ^/wiki/(.*)$        http://crazylinux.de/$1 [R=301,L]

the browser will see the difference

Redirect visitor by domain name

In some cases the same web site is accessible by different addresses, like domain.com, www.domain.com, www.domain2.com and we want to redirect it to one address.

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]

In this case the requested URL http://domain.com/foo.html would redirected to the URL http://www.domain.com/foo.html.

Force SSL-Redirect (for special directory)

How to redirect http-traffic automatically to https

RewriteEngine on
#RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTPS} off

#for a special directory
RewriteRule ^/administrator(.*)$ https://%{SERVER_NAME}/administrator$1 [R,L]

#or for the whole server
RewriteRule ^/(.*)$ https://%{SERVER_NAME}/$1 [R,L]


Redirect all requests to a file (e.g. for maintenance)

found on http://syslog.warten.de/2008/10/redirect-aller-webseiten-auf-e.html

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/offline\.php$
RewriteRule (^$|\.(html|php)$) http://www.example.com/offline.php [L]
</IfModule>



Links

http://www.widexl.com/scripts/documentation/mod_rewrite.html

Keywords: apache,mod_rewrite,file,rewrite,url,save,saving,htaccess,ssl,redirect,http,https,httpd.conf,443,80,seo