2011-10-10 49 views
2

使用模板我有這樣的.htaccess mod_rewrite的代碼,使我的網址漂亮:的.htaccess mod_rewrite的豁免

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteRule ^posts.php$ posts.php [L] 

# Rewrite www to no-www domain 
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
RewriteRule .* http://%1%{REQUEST_URI} [R=301,L] 

# Rewrite multiple slashes with single slash after domain 
RewriteCond %{THE_REQUEST} ^[A-Z]+\s//+(.*)\sHTTP/[0-9.]+$ [OR] 
RewriteCond %{THE_REQUEST} ^[A-Z]+\s(.*/)/+\sHTTP/[0-9.]+$ 
RewriteRule .* http://%{HTTP_HOST}/%1 [R=301,L,NE] 

# Rewrite multiple slashes with single slash in URL 
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$ 
RewriteRule . %1/%2 [R=301,NE,L] 

# Remove slash from URL end 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} ^(.+)/$ 
RewriteRule ^.+/$ %1 [R=301,NE,L] 

# Rewrite backslash with slash 
## Works on FF with using AllowEncodedSlashes On in content/httpd.conf 
RewriteCond %{REQUEST_URI} ^(.*)\\(.*)$ 
RewriteRule .* %1/%2 [R=301,NC,L] 

# Rewrite query string, Ajax crawling 
RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*)$ 
RewriteRule .*$ %{REQUEST_URI}%1? [R=301,L] 
RewriteCond %{QUERY_STRING} ^.+$ 
RewriteCond %{QUERY_STRING} !^url= 
RewriteCond %{QUERY_STRING} !api 
RewriteRule .*$ %{REQUEST_URI}? [R=301,L] 

# Rewrite space with dash 
RewriteCond %{REQUEST_URI} ^([^\ ]*)\ (.*)$ 
RewriteRule .* %1-%2 [R=301,L] 

# Rewrite underscore with dash 
RewriteCond %{REQUEST_URI} ^([^\_]*)\_(.*)$ 
RewriteRule .* %1-%2 [R=301,L] 

# Remove dot 
RewriteCond %{REQUEST_URI} ^([^\.]*)\.(.*)$ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule .* %1%2 [R=301,L] 

# Remove comma 
RewriteCond %{REQUEST_URI} ^([^\,]*)\,(.*)$ 
RewriteRule .* %1%2 [R=301,L] 

# Remove dash before slash 
RewriteCond %{REQUEST_URI} ^(.*)\-/(.*)$ 
RewriteRule ^(.*)\-/(.*)$ %1/%2 [R=301,L] 

# Remove dash after slash 
RewriteCond %{REQUEST_URI} ^(^\.)\/-(.*)$ 
RewriteRule ^(.*)\/-(.*)$ %1/%2 [R=301,L] 

# Remove .php extension 
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]+/)*[^.]+\.php(\?[^\ ]*)?\ HTTP/ [NC] 
RewriteRule ^(([^/]+/)*[^.]+)\.php$ http://%{HTTP_HOST}/%1$1 [R=301,L] 

# Rewrite uppercase letter URL to lowercase with content/httpd.conf RewriteMap lc int:tolower 
## Solution without httpd.conf RewriteMap in github.com/laukstein/ajax-seo/wiki/Lowercase-URL 
RewriteCond %{REQUEST_URI} .+ 
RewriteRule ^[^A-Z]*[A-Z] ${lc:%0} [R=301,L] 

# Block folder access that begins with a period (like .git, .svn) 
RewriteRule "(^|/)\." - [F] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^api/?([^\./]*)$ ?api&url=$1 [L,QSA] 
RewriteRule ^([^.]*)$ ?url=$1 [L,QSA] 

RewriteRule .* - [E=HTTP_IF_MODIFIED_SINCE:%{HTTP:If-Modified-Since}] 
RewriteRule .* - [E=HTTP_IF_NONE_MATCH:%{HTTP:If-None-Match}] 

我已經成功地創建豁免,允許posts.php文件被訪問 - 但我無法知道如何讓我的頁面訪問存儲在/ uploads /路徑中的所有圖像。

非常感謝,邁克

+0

等一下。 .htaccess處理您的**傳入** SEO格式的URI並將它們轉換爲服務器和腳本語言(例如PHP)可以處理的動態非SEO格式。您的代碼看起來像是在嘗試將_outgoing_ links _to_SEO格式轉換,這是行不通的。你究竟想要做什麼? –

回答

3

使用-當你不想要的URL重寫。這個規則在您的文件的頂部(或任何其他規則,你想先處理)將做的伎倆:

RewriteRule ^uploads/ - [L] 
+0

完美 - 謝謝 –