Apache mod_rewrite RewriteRule



Doação

pagerank
O que você gostaria de ver nesta página?

Apache mod_rewrite RewriteRule

Exemplos de RewriteRule do Módulo Apache 'mod_rewrite' para fazer Redirecionamento de Url (URL Rewriting Engine)




RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/(index\.asp¦default\.asp)$ -f
RewriteRule (.*) http://www.yourdomain.com/$1/%1 [R=301,L]

Internal rewrite version (does not show in user's browser address bar, and does not update search engine URL listings):

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{REQUEST_FILENAME}/(index\.asp¦default\.asp)$ -f
RewriteRule (.*) /$1/%1 [L]


The idea is, using such a URL
http://host.net/aa/bb/cc/dd
is better than usual php thing
http://host.net/index.php?aa=bb&cc=dd
And with mod_rewrite,
RewriteRule ^/*index.php - [L]
RewriteRule ^/*(([^/]+)/+([^/]+)/+([^/]+)/*(.*)$ index.php?$1=$2&$3=$4 [L]


Search pages in more than one directory


Description:

Sometimes it is necessary to let the webserver search for pages in more than one directory. Here MultiViews or other techniques cannot help.
Solution:

We program a explicit ruleset which searches for the files in the directories.

RewriteEngine on

# first try to find it in custom/...
# ...and if found stop and be happy:
RewriteCond /your/docroot/dir1/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /your/docroot/dir1/$1 [L]

# second try to find it in pub/...
# ...and if found stop and be happy:
RewriteCond /your/docroot/dir2/%{REQUEST_FILENAME} -f
RewriteRule ^(.+) /your/docroot/dir2/$1 [L]

# else go on for other Alias or ScriptAlias directives,
# etc.
RewriteRule ^(.+) - [PT]

Alterando a Língua

RewriteCond %{HTTP:Accept-Language} ^.*(de|es|fr|it|ja|ru|en).*$ [NC]
RewriteRule ^(.*)$ - [env=lang:%1]


To install this recipe

  • download fastcache.php. to your cookbook directory
  • add the following line to your config.php file:
    include_once("$FarmD/cookbook/fastcache.php");
  • edit your server settings (see the CleanUrls recipe for instructions where to find them) as follows:

mod_rewrite


The following assumes that you have some idea of what you're doing and that you have $EnablePathInfo set. These rules are based on the CleanUrls recipe. Take note that you'll need to replace the text in bold with whatever's appropriate for your setup.

RewriteEngine On
# Define the rewrite base. This is the URL of the directory that the
# .htaccess file (if using) resides in
RewriteBase /url/path/to/rewrite/root
# Catch requests for index.anything
RewriteRule ^index / [R=301]

# Non-capital first letter means that it's not a wiki page
RewriteRule ^([a-z].*)$ $1 [L]


## Define the rules that exclude things from the cache:
# If any of these conditions are true ...

# Posting a form request
RewriteCond %{REQUEST_METHOD} POST [OR]
# A session exists -> the user is signed in
RewriteCond %{HTTP_COOKIE} PHPSESSID [OR]
# A query string exists; ie. we're not just viewing a page
RewriteCond %{QUERY_STRING} .

# ... serve the file using pmwiki.php
RewriteRule ^(.*)$ relative/url/path/to/pmwiki.php?n=$1 [QSA,L]


## We're this far in the script if it's ok to serve files from the cache

# Root means that we want the wiki homepage
RewriteCond %{REQUEST_URI} ^/$
# Does the file exist?
# Change 'Main.HomePage' here if you're using a different page
RewriteCond /absolute/path/to/htmlcache/Main.HomePage.html -f
# If so, serve it.
# Change 'Main.HomePage' here if you're using a different page
RewriteRule ^$ relative/url/path/to/htmlcache/Main.HomePage.html [L]

# No . or / in the URL means that we want the group main page
RewriteCond %{REQUEST_URI} ^/([^./?]+)[./]?$
# Does the file exist?
# Change '%1.%1' here if you're using a different group main page format
RewriteCond /absolute/path/to/htmlcache/%1.%1.html -f
# If so, serve it.
RewriteRule ^([^./?]+)[./]?$ relative/url/path/to/htmlcache/$1.$1.html [L]

# We want Group.Page
RewriteCond %{REQUEST_URI} ^/([^./]+)[./]([^./]+)/?$
# Does the file exist?
RewriteCond /absolute/path/to/htmlcache/%1.%2.html -f
# If so, serve it.
RewriteRule ^([^./]+)[./]([^./]+)/?$ relative/url/path/to/htmlcache/$1.$2.html [L]


# Cache misses and anything that doesn't fit the above goes to pmwiki.php
RewriteRule ^(.*)$ relative/url/path/to/pmwiki.php?n=$1 [QSA,L]



mod_rewrite 1.3
rewriteguide 1.3
mod_rewrite 2.0
rewriteguide 2.0
rewrite_guide_advanced
Pesquisa Google


Add Favorites / Bookmark
importar no delicious






Ganhe dinheiro com links patrocinados

Aumente seu pagerank comprando Link

Hospedagem de Páginas Grátis

Ganhe com seu site!

2GB Grátis para Online Backup!

Links patrocinados:

Poker Regras

Poker

cores html
webdesign
poker de graça
importar no delicious
sputnix


Bookmark to:


Apache mod_rewrite RewriteRule

Exemplos de RewriteRule do Módulo Apache 'mod_rewrite' para fazer Redirecionamento de Url (URL Rewriting Engine)






CID10: a09 b34_9 c18_9 c44_9 c61 c73 f06_8 f19 f20_0 f29 f31_8 f31_9 f32 f32_0 f32_2 f33_1 f40_9 f41_1 f41_9 f42_2 f43_1 f43_2 f60_3 f71_0 f72 f72_8 f84_0 f90_1 i10 j18 m19_0 m25_5 m41_1 m46_9 m47_2 m47_8 m48_0 m50_1 m53_1 m54_1 m54_4 m54_5 m65 m75_1 m75_2 m77_1 m79_0 m79_1 n60_2 n87_1 q90 r42 s60_0 z31_0 z43_1 z43_5 z54_0 CID-10