【问题标题】:Move .htaccess wordpress directives to apache config file将 .htaccess wordpress 指令移动到 apache 配置文件
【发布时间】:2020-06-25 14:34:22
【问题描述】:

我试图避免在 WordPress 中使用 .htaccess 文件。我试图将所有指令移动到一个 apache 配置文件中,将它们包含在标签中,但它不起作用。

我正在使用 Apache/2.4.37

我目前在 apache 的配置是:

<VirtualHost *:443>
    ServerAdmin webmaster@mydomain.com
    DocumentRoot /var/www/html/myweb
    ServerName myweb.mydomain.com
    ErrorLog logs/myweb.com-error_log
    CustomLog logs/myweb.com-access_log common

    SSLCertificateFile /etc/httpd/certificate/myweb.crt
    SSLCertificateKeyFile /etc/httpd/certificate/myweb.key

    <Directory "/var/www/html/myweb">
        RewriteEngine On
        RewriteBase /
        RewriteRule ^index\.php$ - [L]
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
   </Directory>
</VirtualHost>

有什么方法可以避免 .htaccess 重写?

【问题讨论】:

标签: wordpress apache .htaccess


【解决方案1】:

移动代码时需要考虑到情况存在一些细微差别。

  1. RewriteRule ^index\.php$ - [L] 在全局配置中没有意义,因为 RewriteRules 在 absolute path 上工作,而不是在 相对路径 上工作的分布式配置文件。 . 所以应该是RewriteRule ^/index\.php$ - [L],注意前面的斜线。

  2. RewriteBase / 在全局配置中没有任何意义,删除那个。

  3. 将代码块移出&lt;Directory ...&gt;...&lt;/Directory&gt; 块。这些规则应该在全球范围内应用。

  4. 可以L 标志替换为END 标志。您可能需要查看相关文档。

而且你需要注意 wordpress 很高兴,即使它不会弄乱配置文件。

【讨论】:

    猜你喜欢
    • 2012-05-21
    • 2022-01-22
    • 1970-01-01
    • 2020-12-23
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 2016-03-26
    • 1970-01-01
    相关资源
    最近更新 更多