简体   繁体   English

apache基本身份验证中断.htaccess中的重写

[英]apache basic auth breaks rewrite in .htaccess

rewriting works fine until we add auth to htaccess. 重写工作正常,直到将auth添加到htaccess中为止。 Is auth formatted correctly? 认证格式正确吗? Why would rewrite work before adding auth? 为什么要在添加auth之前重写工作?

Request params at the site controller with no auth: 在没有身份验证的情况下在站点控制器上请求参数:

[id] => 433    [type] => city

Params after auth added and the user authenticated: 添加身份验证和用户身份验证后的参数:

[site/query]

Sample query url that works without auth: 无需身份验证即可使用的示例查询网址:

http://www.website.com/site/query?type=city&id=433

The .htaccess with basic auth at the bottom: 底部具有基本身份验证的.htaccess:

# any visits not coming from this official URL should be rerouted; AJAX cross-domain, www.website.com is not the same as our.company.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.website\.com$ [NC]
RewriteRule ^(.*)$ http://www.website.com/$1 [R=301,L]

# route all requests that are NOT static files, through index.php to make the /nice/urls/ work
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]

# disable file listings for directories
Options -Indexes

# disable the fetching of .phtm
<Files ~ "\.phtml$">
  Order allow,deny
  Deny from all
</Files>

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:modules|system)\b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

AuthType Basic
AuthName "Password required"
AuthUserFile /maps/scorp/main/.htpasswd
Require valid-user

I've got no answer to your nice questions but I hope I found a solution. 对于您的问题,我没有任何答案,但我希望找到解决方案。 :) :)

IMHO in your .htaccess the authorisation will take the advantage. 恕我直言,您的.htaccess中的授权将被利用。 It's a kinda tricky but you can break the priority by enclosing the "Require valid-user" directive into block <Files>. 这有点棘手,但是您可以通过将“ Require valid-user”指令包含在块<Files>中来破坏优先级。 Eg: 例如:

<Files "*.phtml">
    Require valid-user
</Files>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM