htaccess的mod_rewrite的豁免 [英] .htaccess mod_rewrite exemptions

查看:161
本文介绍了htaccess的mod_rewrite的豁免的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用模板我有这样的.htaccess的mod_rewrite code,使我的URL pretty的:

Using a template I have this .htaccess mod_rewrite code that makes my URL's pretty:

<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文件 - 但是我无能如何让我的网页来访问存储在/上传/路径下的所有图片

I've managed to create an exemption to allow the posts.php file to be accessed - However I am clueless on how to allow my pages to access all images stored in the /uploads/ path.

非常感谢,迈克

推荐答案

使用 - 因为当你不想被改写的URL。这条规则在你文件的顶部(或之后的任何其他规则,你想首先处理)会做的伎俩:

Use - for when you don't want the URL to be rewritten. This rule at the top of your file (or after any other rules you want processed first) would do the trick:

RewriteRule ^uploads/ - [L]

这篇关于htaccess的mod_rewrite的豁免的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆