I'm trying to avoid .htaccess files in WordPress. I tried to move all directives to an apache config file, enclosing them into tags, but it doesn't work.
I'm using Apache/2.4.37
My current config at apache is:
<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?
You need to consider that there are some slight differences in the situation when you move the code.
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.
RewriteBase /
does not make any sense in the global configuration, remove that one.
Move the code block outside the <Directory...>...</Directory>
block. The rules should get applied globally.
You could replace the L
flag with the END
flag. 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.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.