ApacheRewrite: Unterschied zwischen den Versionen

Aus crazylinux.de
Zur Navigation springen Zur Suche springen
K (typo)
(ssl-redirect)
Zeile 2: Zeile 2:
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:


RewriteEngine On
<source lang="apache">
RewriteRule ^/downloads/(.*) /getFile.php?filename=$1 [NE]
RewriteEngine On
RewriteRule ^/downloads/(.*) /getFile.php?filename=$1 [NE]
</source>


mod_rewrite will translate the url, and the browser (and the user) won't know the difference.
mod_rewrite will translate the url, and the browser (and the user) won't know the difference.
Zeile 11: Zeile 13:
old: http://crazylinux.de/wiki/TAR<br>
old: http://crazylinux.de/wiki/TAR<br>
new: http://crazylinux.de/TAR
new: 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>


the browser will see the difference
the browser will see the difference
Zeile 18: Zeile 21:
=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.
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
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R,L]
</source>


RewriteEngine On
In this case the requested URL http://domain.com/foo.html would redirected to the URL http://www.domain.com/foo.html.
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=
<source lang="apache">
RewriteEngine on
#RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTPS} off
RewriteRule ^/administrator(.*)$ https://%{SERVER_NAME}/administrator$1 [R,L]
</source>


=Links=
=Links=
Zeile 31: Zeile 43:
Keywords: apache,mod_rewrite,file,rewrite,url,save,saving,htaccess
Keywords: apache,mod_rewrite,file,rewrite,url,save,saving,htaccess


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

Version vom 19. April 2008, 23:59 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.


external redirect

old: http://crazylinux.de/wiki/TAR
new: 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

RewriteEngine on
#RewriteCond %{SERVER_PORT} !^443$
RewriteCond %{HTTPS} off
RewriteRule ^/administrator(.*)$ https://%{SERVER_NAME}/administrator$1 [R,L]

Links

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


Keywords: apache,mod_rewrite,file,rewrite,url,save,saving,htaccess