.htaccess
Aus Mein Wiki
Sebra  (Diskussion | Beiträge)  (→Url-Rewriting mit .htaccess)  | 
		Sebra  (Diskussion | Beiträge)   (→Cheat Sheets)  | 
		||
| Zeile 3: | Zeile 3: | ||
= Settings / Debug per .htaccess =  | = Settings / Debug per .htaccess =  | ||
=== Turn on Error Reporting with .htaccess ===  | === Turn on Error Reporting with .htaccess ===  | ||
| + | |||
  php_flag display_errors on  |   php_flag display_errors on  | ||
  php_value error_reporting 7  |   php_value error_reporting 7  | ||
| - | = Url-Rewriting mit .htaccess =  | + | = Url-Rewriting / Speaking-Urls mit .htaccess =  | 
| + | == Cheat Sheets ==  | ||
* mod_rewrite Quick Reference and Cheat Sheet  | * mod_rewrite Quick Reference and Cheat Sheet  | ||
** http://semlabs.co.uk/journal/mod_rewrite-quick-reference-and-cheat-sheet  | ** http://semlabs.co.uk/journal/mod_rewrite-quick-reference-and-cheat-sheet  | ||
| + | * Mod_Rewrite Variables Cheatsheet  | ||
| + | ** http://www.askapache.com/htaccess/mod_rewrite-variables-cheatsheet.html  | ||
* http://stackoverflow.com/questions/2803040/apache-rewrite-mod-rewriterule-path-and-query-string  | * http://stackoverflow.com/questions/2803040/apache-rewrite-mod-rewriterule-path-and-query-string  | ||
| - | |||
| + | |||
| + | * http://www.askapache.com/htaccess/modrewrite-tips-tricks.html  | ||
| + | |||
| + | * http://www.workingwith.me.uk/articles/scripting/mod_rewrite  | ||
| + | |||
| + | * http://www.kb.mediatemple.net/questions/85/Using+.htaccess+rewrite+rules#gs  | ||
| + | |||
| + | == Tools ==  | ||
| + | * Mod Rewrite Generator  | ||
| + | ** http://www.generateit.net/mod-rewrite/  | ||
| + | |||
| + | == Samples ==  | ||
| + | |||
| + |  #Sending requests to a php script ^  | ||
| + |  #This .htaccess rewrite example invisibly rewrites requests for all Adobe pdf   | ||
| + |  #files to be handled by /cgi-bin/pdf-script.php  | ||
| + |  RewriteRule ^(.+)\.pdf$  /cgi-bin/pdf-script.php?file=$1.pdf [L,NC,QSA]  | ||
| + | |||
| + |  #Redirects all files that end in .html to be served from filename.php so it   | ||
| + |  #looks like all your pages are .html but really they are .php  | ||
| + |  RewriteRule ^(.*)\.html$ $1.php [R=301,L]  | ||
| + | |||
  RewriteEngine On  |   RewriteEngine On  | ||
  RewriteCond %{HTTP_USER_AGENT} ^.*mobile.*$ [NC]  |   RewriteCond %{HTTP_USER_AGENT} ^.*mobile.*$ [NC]  | ||
| Zeile 21: | Zeile 46: | ||
  RewriteRule /path/index.php /path/iphone.php?extra=param [QSA,L]  |   RewriteRule /path/index.php /path/iphone.php?extra=param [QSA,L]  | ||
| - | '  | + |  RewriteCond %{REQUEST_FILENAME} !-f  | 
| + |  RewriteCond %{REQUEST_FILENAME} !-d  | ||
| + |  RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]  | ||
| + | |||
| + | === subdomain to folder/directory ===  | ||
| + | Is it possible to use .htaccess to rewrite a sub domain to a directory?  | ||
| + | Example: http://sub.domain.com/ shows the content of http://domain.com/subdomains/sub/  | ||
| + | |||
| + |  RewriteEngine on  | ||
| + |  RewriteCond %{HTTP_HOST} ^sub.domain.com  | ||
| + |  RewriteRule ^(.*)$ http://domain.com/subdomains/sub/$1 [L,NC,QSA]  | ||
| + |  #For a more general rule (that works with any subdomain, not just sub)   | ||
| + |  #replace the last two lines with this:  | ||
| + |  RewriteEngine on  | ||
| + |  RewriteCond %{HTTP_HOST} ^(.*)\.domain\.com  | ||
| + |  RewriteRule ^(.*)$ http://domain.com/subdomains/%1/$1 [L,NC,QSA]  | ||
| + | |||
| + | === ... ===  | ||
| + |  ###################################################  | ||
| + |  # Turn the RewriteEngine on.                      #  | ||
| + |  ###################################################  | ||
| + |  RewriteEngine on  | ||
| + |  ###################################################  | ||
| + |  # Add a leading www to domain if one is missing.  #  | ||
| + |  ###################################################  | ||
| + |  # If this rule is used, the rewriting stops here  #  | ||
| + |  # and then restarts from the beginning with the   #  | ||
| + |  # new URL                                         #  | ||
| + |  ###################################################  | ||
| + | |||
| + | RewriteCond %{HTTP_HOST} !^www\.  | ||
| + | RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]  | ||
| + | |||
| + | ###################################################  | ||
| + | # Do not process images or CSS files further      #  | ||
| + | ###################################################  | ||
| + | # No more processing occurs if this rule is       #  | ||
| + | # successful                                      #  | ||
| + | ###################################################  | ||
| + | |||
| + | RewriteRule \.(css|jpe?g|gif|png)$ - [L]  | ||
| + | |||
| + | ###################################################  | ||
| + | # Add a trailing slash if needed                  #  | ||
| + | ###################################################  | ||
| + | # If this rule is used, the rewriting stops here  #  | ||
| + | # and then restarts from the beginning with the   #  | ||
| + | # new URL                                         #  | ||
| + | ###################################################  | ||
| + | |||
| + | RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$  | ||
| + | RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L]  | ||
| + | |||
| + | ###################################################  | ||
| + | # Rewrite web pages to one master page            #  | ||
| + | ###################################################  | ||
| + | # /somepage/            => master.php             #  | ||
| + | #                            ?page=somepage       #  | ||
| + | # /somesection/somepage => master.php             #  | ||
| + | #                            ?section=somesection #  | ||
| + | #                            &page=somepage       #  | ||
| + | # /somesection/somesub/somepage/                  #  | ||
| + | #                       => master.php             #  | ||
| + | #                            ?section=somesection #  | ||
| + | #                            &subsection=somesub  #  | ||
| + | #                            &page=somepage       #  | ||
| + | ###################################################  | ||
| + | # Variables are accessed in PHP using             #  | ||
| + | # $_GET['section'], $_GET['subsection'] and       #  | ||
| + | # $_GET['page']                                   #  | ||
| + | ###################################################  | ||
| + | # No more processing occurs if any of these rules #  | ||
| + | # are successful                                  #  | ||
| + | ###################################################  | ||
| + | |||
| + | RewriteRule ^([^/\.]+)/?$ /master.php?page=$1 [L]  | ||
| + | RewriteRule ^([^/\.]+)/([^/\.]+)/?$ /master.php?section=$1&page=$2 [L]  | ||
| + | RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ /master.php?section=$1&subsection=$2&page=$3 [L]  | ||
= Authentifizierung mit .htaccess =  | = Authentifizierung mit .htaccess =  | ||

