AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题 / 615889
Accepted
CaptSaltyJack
CaptSaltyJack
Asked: 2014-07-28 18:36:27 +0800 CST2014-07-28 18:36:27 +0800 CST 2014-07-28 18:36:27 +0800 CST

Apache 重写以删除“www”不起作用(全局)

  • 772

我已经获取了Apache Server Configs全局.htaccess文件并将其放在我的 Web 服务器上,如/etc/apache2/apache-server-configs.conf. 然后在我的/etc/apache2/apache2.conf文件中,我的文件末尾有这个:

# Include of directories ignores editors' and dpkg's backup files,
# see the comments above for details.

# Apache Server Configs
Include apache-server-configs.conf

# Include generic snippets of statements
Include conf.d/

# Include the virtual host configurations:
Include sites-enabled/

该文件apache-server-configs.conf已正确包含,但此代码块无法正常工作:

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

(此块上方有一条RewriteEngine on语句,有几行)如果我将它放在单个域的.htaccess文件中,它会按预期工作。但在全球范围内,它什么也没做。我尝试使用调试RewriteLog,但访问我的网站时日志文件为空。

我错过了什么?

Debian 7.5,阿帕奇 2.2.22

编辑 8/2/2014:添加更多信息


还值得注意的是,如果我在其中包含一个 conf 文件/etc/apache2/apache2.conf并将任何RewriteRule调用放入包含的文件中,它们都不起作用,期间。conf 文件中的其他内容可以正常工作,但重写却不行。

test.com 虚拟主机文件:

<VirtualHost *:80>
  # Admin email, Server Name (domain name), and any aliases
  ServerAdmin [email protected]
  ServerName  test.com
  ServerAlias www.test.com
  Options -Indexes

  <IfModule mpm_itk_module>
    AssignUserID bob bob
  </IfModule>

  # Index file and Document Root (where the public files are located)
  DirectoryIndex index.html index.php
  DocumentRoot /home/bob/www/test.com

  # Log file locations
  LogLevel warn
  ErrorLog  /home/bob/logs/test.com/error.log
  CustomLog /home/bob/logs/test.com/access.log combined
</VirtualHost>

<VirtualHost *:443>
     SSLEngine On
     SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem
     SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key
     #SSLCertificateChainFile /etc/ssl/test.com/ca-bundle

     ServerAdmin [email protected]
     ServerName test.com
     ServerAlias www.test.com
     Options -Indexes

     <IfModule mpm_itk_module>
       AssignUserID bob bob
     </IfModule>

     DocumentRoot /home/bob/www/test.com
     ErrorLog /home/bob/logs/test.com/error.log
     CustomLog /home/bob/logs/test.com/access.log combined
</VirtualHost>
apache-2.2
  • 1 1 个回答
  • 925 Views

1 个回答

  • Voted
  1. Best Answer
    Jaap Haagmans
    2014-07-28T23:18:04+08:002014-07-28T23:18:04+08:00

    根据Apache 文档,重写条件默认情况下不被子 Virtualhost 块继承。取自文档,建议可以将它们设置为继承,如下所示:

    RewriteEngine On
    RewriteOptions Inherit
    

    您必须在需要继承您在主配置文件中设置的重写规则的每个虚拟主机上进行设置。

    • 1

相关问题

  • Apache Django Mod_Wsgi - 自动重新加载应用程序

  • Apache:对多个虚拟主机使用相同的目录指令

  • Apache 上的子域不工作 - 找不到服务器

  • PHP 作为 CGI 还是 Apache 模块?

  • 避免将某些丢失的文件记录到 Apache2 错误日志中

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve