简体   繁体   English

将 .htaccess wordpress 指令移至 apache 配置文件

[英]Move .htaccess wordpress directives to apache config file

I'm trying to avoid .htaccess files in WordPress.我试图避免 WordPress 中的 .htaccess 文件。 I tried to move all directives to an apache config file, enclosing them into tags, but it doesn't work.我试图将所有指令移动到 apache 配置文件,将它们包含在标签中,但它不起作用。

I'm using Apache/2.4.37我正在使用 Apache/2.4.37

My current config at apache is:我在 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>

Is there any way to avoid .htaccess rewrites?有什么办法可以避免 .htaccess 重写?

You need to consider that there are some slight differences in the situation when you move the code.您需要考虑在移动代码时情况存在一些细微差别。

  1. RewriteRule ^index\.php$ - [L] does not make sense in the global configuration, since RewriteRules work on absolute path there as opposed to distributed configuration files where they work on relative paths ... So it should be RewriteRule ^/index\.php$ - [L] instead, note the leading slash. RewriteRule ^index\.php$ - [L]在全局配置中没有意义,因为 RewriteRule 在绝对路径上工作,而不是在相对路径上工作的分布式配置文件......所以它应该是RewriteRule ^/index\.php$ - [L]相反,请注意前导斜杠。

  2. RewriteBase / does not make any sense in the global configuration, remove that one. RewriteBase /在全局配置中没有任何意义,删除那个。

  3. Move the code block outside the <Directory...>...</Directory> block.将代码块移到<Directory...>...</Directory>之外 The rules should get applied globally.这些规则应该在全球范围内应用。

  4. You could replace the L flag with the END flag.可以L标志替换为END标志。 You may want to take a look into the documentation about that.您可能想查看有关此的文档。

And you need to take care that wordpress is happy even if it can not mess around with configuration files.而且您需要注意 wordpress 很高兴,即使它不能乱用配置文件。

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

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