【问题标题】:htaccess rewrite rule exclude directory from wildcardhtaccess 重写规则从通配符中排除目录
【发布时间】:2018-01-08 04:43:53
【问题描述】:

我有一个带有 RewriteRule 的 htaccess,如果您访问我的域,它将定向到公共文件夹。 在下面查看我的代码

RewriteEngine on
RewriteRule ^(.*) public/$1 [L]

现在我想从通配符中排除演示目录 (www.mydomain.com/demo)。 我尝试使用此代码但没有用

RewriteRule ^demo($|/) - [L]

还有这个

RewriteRule /demo/$1 -f

完整的htaccess代码

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/demo
RewriteRule ^(.*) public/$1 [L]

# Deflate Compression by FileType
<IfModule mod_deflate.c>
 AddOutputFilterByType DEFLATE text/plain
 AddOutputFilterByType DEFLATE text/html
 AddOutputFilterByType DEFLATE text/xml
 AddOutputFilterByType DEFLATE text/css
 AddOutputFilterByType DEFLATE text/javascript
 AddOutputFilterByType DEFLATE application/xml
 AddOutputFilterByType DEFLATE application/xhtml+xml
 AddOutputFilterByType DEFLATE application/rss+xml
 AddOutputFilterByType DEFLATE application/atom_xml
 AddOutputFilterByType DEFLATE application/javascript
 AddOutputFilterByType DEFLATE application/x-javascript
 AddOutputFilterByType DEFLATE application/x-shockwave-flash
</IfModule>

# Set browser caching to 1 month
<IfModule mod_expires.c>
 ExpiresActive On
 ExpiresByType text/css "access plus 1 month"
 ExpiresByType text/javascript "access plus 1 month"
 ExpiresByType text/html "access plus 1 month"
 ExpiresByType application/javascript "access plus 1 month"
 ExpiresByType image/gif "access plus 1 month"
 ExpiresByType image/jpeg "access plus 1 month"
 ExpiresByType image/png "access plus 1 month"
 ExpiresByType image/x-icon "access plus 1 month"
</IfModule>

<ifmodule mod_headers.c>
 <filesmatch "\\.(ico|jpe?g|png|gif|swf)$">
  Header set Cache-Control "max-age=2592000, public"
 </filesmatch>
 <filesmatch "\\.(css)$">
  Header set Cache-Control "max-age=604800, public"
 </filesmatch>
 <filesmatch "\\.(js)$">
  Header set Cache-Control "max-age=216000, private"
 </filesmatch>
</ifmodule>

希望有人帮助我。

谢谢

【问题讨论】:

    标签: apache .htaccess


    【解决方案1】:
    RewriteCond %{REQUEST_URI} !^/demo
    RewriteRule ^(.*) public/$1 [L]
    

    RewriteCond %{REQUEST_URI} !^/demo 测试请求 uri 是否不以 /demo 开头,然后应用下一个 RewriteRule

    【讨论】:

    • 我尝试在上面使用但没有用这是我的代码RewriteEngine on RewriteCond %{REQUEST_URI} !^/demo RewriteRule ^(.*) public/$1 [L]
    • 不排除/demo文件夹?您可以在问题中发布完整的 .htaccess 文件吗?
    • 尝试在RewriteEngine on之后添加RewriteBase /
    • 嗨 Ben,我又试了一次,但还是不行这是我当前的 htaccess 代码RewriteEngine on RewriteBase / RewriteCond %{REQUEST_URI} !^/sequencing RewriteRule ^(.*) public/$1 [L]
    猜你喜欢
    • 2010-12-23
    • 1970-01-01
    • 2015-08-03
    • 1970-01-01
    • 2014-05-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多