我在其中一个 vhost 上进行了以下设置:
...<VirtualHost *:80>
ServerName cloud.domain.de
ServerAdmin webmaster@domain.de
ServerSignature Off
Alias "/.well-known/acme-challenge" "/var/www/domain.de/vh-www/htdocs/public/.well-known/acme-challenge"
<Directory "/var/www/domain.de/vh-www/htdocs/public/.well-known/acme-challenge">
Require all granted
ForceType 'text/plain'
</Directory>
<ifmodule mod_rewrite.c>
RewriteEngine On
RewriteCond %(REQUEST_URI) !/\.well\-known/acme\-challenge/?.*
RewriteCond %{HTTPS} off
# RewriteRule ^\.well-known/acme-challenge/([A-Za-z0-9-]+)/?$ - [L]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</ifmodule>...
Run Code Online (Sandbox Code Playgroud)
我想要实现的是,当http://cloud.domain.de/.well-known/acme-challenge/
访问url 时,mod_rewrite 不会重写 URL 。
我已经尝试了不同的方法,其中之一是上面注释掉的 RewriteRule,但似乎没有任何效果:服务器每次都将其重写为 https。
当我出于测试目的禁用重写时,我可以很好地访问别名 URL...
如何实现不被重写的特定 URL?
我想 301 将所有 example.org 重定向到 www.example.org。下面的例子就是这样做的,但是它有很多噪音,因此很难维护并且容易出错:
<VirtualHost 192.0.2.123:80>
ServerName example.org
RedirectPermanent / http://www.example.org
</VirtualHost>
<VirtualHost 192.0.2.123:80>
ServerName www.example.org
DocumentRoot /usr/local/www/example
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
您是否碰巧知道上面的整个内容是否有一些更短的版本?
像这样的伪配置:
<VirtualHost 192.0.2.123:80>
ServerName www.example.org
ServerAlias example.org
# Redirect-Every-ServerAlias-To-ServerName
DocumentRoot /usr/local/www/example
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)
这样我就只需要提供应该重定向到的每个子域ServerAlias
?
我想尝试mod_alias
而不是mod_rewrite
几个简单的重定向规则,但是当输入.htaccess
. 是否可能mod_alias
未在服务器上加载或启用?
我怎么知道?
我有一个全局条目
Alias /.well-known/acme-challenge /var/www/letsencrypt/.well-known/acme-challenge/
Run Code Online (Sandbox Code Playgroud)
在我的 apache 配置中,在任何虚拟主机之外。这样,上面的别名对所有虚拟主机都有效。不幸的是,仍有一些虚拟主机无法按预期工作,例如由于重定向、身份验证要求等。
有没有办法告诉 apache 在读取特定虚拟主机的配置之前考虑这个别名?
比较这两个RedirectMatch
。第一个不起作用:
RedirectMatch 302 ^/redirect\.php[?]page=(.+)$ http://somewhereelse.com/$1
Run Code Online (Sandbox Code Playgroud)
与此相反,它将重定向到http://somewhereelse.com/?page=wherever
:
RedirectMatch 302 ^/redirect\.php([?]page=.+)?$ http://somewhereelse.com/$1
Run Code Online (Sandbox Code Playgroud)
是否RedirectMatch
只匹配 URI 而不是查询字符串?Apache 的文档在这方面有点含糊。我想要做的是提取page
查询参数并使用它重定向到另一个站点。
这是可能的RedirectMatch
还是我必须使用RewriteCond
+ RewriteRule
?
我在 Debian(在测试服务器中)的 Apache2 上设置了 mod_rewrite 和 mod_alias。
我有以下重写代码/etc/apache2/sites-available/default
:
<Directory />
Options FollowSymLinks
AllowOverride All
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(php|html|css|js|gif|png|jpe?g)$
RewriteRule (.*)$ /index.php [L]
</Directory>
Run Code Online (Sandbox Code Playgroud)
我有以下别名代码,默认情况下从 phpmyadmin 包(通过加载apt-get install phpmyadmin
并位于/etc/apache2/conf.d/phpmyadmin.conf
)中设置:
Alias /phpmyadmin /usr/share/phpmyadmin
Run Code Online (Sandbox Code Playgroud)
每次我加载http://my.test.server/phpmyadmin 时,它都会转到http://my.test.server/index.php而不是别名(绕过/忽略?)。
如何设置排除规则以允许别名通过(即使别名设置在不同的文件中?)
Apache 2.2(在运行 cPanel 的服务器上)似乎忽略了返回 410 状态的指令。
这发生在 mod_alias 的 Redirect(使用410
或gone
)和 mod_rewrite 的 RewriteRule(使用[G]
),在 .htaccess 文件中使用。
这有效:
Redirect 302 /somewhere /gone
Run Code Online (Sandbox Code Playgroud)
但这不会:
Redirect 410 /somewhere
Run Code Online (Sandbox Code Playgroud)
该行将被忽略(就像它已被注释一样)并且请求会落入其他规则(将其定向到不相关的通用错误处理脚本)。
类似地,尝试使用带有 [G] 标志的 RewriteRule 不起作用,但是将相同的规则重写为生成 410 的脚本可以 - 所以规则不是问题,它似乎是关于 410/没有表现。
我可以通过让脚本发送 410 来解决它,但这很烦人,我不明白为什么它不起作用。
有任何想法吗?
mod-alias ×7
apache-2.2 ×5
mod-rewrite ×5
apache-2.4 ×2
redirect ×2
httpd.conf ×1
querystring ×1
rewrite ×1
virtualhost ×1