I have setup a apache virtual host using the below script -
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName nvoids.cu.cc
ServerAlias www.nvoids.cu.cc
DocumentRoot /var/www/html/blog
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
Now this is working fine at this url - http://nvoids.cu.cc
which serves the pages from /var/www/html/blog
But the wordpress permalinks are not working for example
http://nvoids.cu.cc/hello/ throws a 404 page.
For that i tried changing the .htaccess file as follows -
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase blog/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . blog/index.php [L]
</IfModule>
But its not working.
You need
AllowOverride All
In your VirtualHost directive to enable use of .htaccess files.
Is the following module enabled in your php.ini which should be uncommented? Do you see any error in your apache error log file?
LoadModule rewrite_module
As answered by Daniel the virtual server conf should be -
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName nvoids.cu.cc
ServerAlias www.nvoids.cu.cc
DocumentRoot /var/www/html/blog
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/html/blog/>
AllowOverride All
allow from all
</Directory>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
The .htaccess file as it is modified by wordpress -
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Related
I've got a question about apache configs or it may be the .httaccess file. I have staging site : staging.witnesstolove.org with https enabled. when I try to go to the site, I'm redirected to stagingwitnesstolove.org and I'm not sure why?
My apache config seems pretty basic:
<VirtualHost *:80>
ServerAdmin accounts#1905newmedia.com
DocumentRoot /home/ubuntu/staging/witnesstolove/current/site/web/
ServerName staging.witnesstolove.org
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/ubuntu/staging/witnesstolove/current/site/web/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
RewriteCond %{SERVER_NAME} =staging.witnesstolove.org
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
I see in devtools that i'm getting a 301 redirect and it says it's being redirected by wordpress.
If I look at the .htaccess file for the site, it's like this:
# BEGIN WordPress
# The directives (lines) between "BEGIN WordPress" and "END WordPress" are
# dynamically generated, and should only be modified via WordPress filters.
# Any changes to the directives between these markers will be overwritten.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Based on the response headers I'm getting back, it sounds like wordpress is redirecting the traffic to the other domain?
Here's the HTTPS config for the site in Apache:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin accounts#1905newmedia.com
DocumentRoot /home/ubuntu/staging/witnesstolove/current/site/web/
ServerName staging.witnesstolove.org
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/ubuntu/staging/witnesstolove/current/site/web/>
Options +FollowSymlinks
AllowOverride All
Require all granted
</Directory>
RewriteEngine on
# Some rewrite rules in this file were disabled on your HTTPS site,
# because they have the potential to create redirection loops.
# RewriteCond %{SERVER_NAME} =staging.witnesstolove.org
# RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
SSLCertificateFile /etc/letsencrypt/live/staging.witnesstolove.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/staging.witnesstolove.org/privkey.pem
Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
my WordPress site becomes 404 not found after I install SSL in
sites-available/default-SSL.conf and this is the code :
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin my#website.go.id
ServerName website.go.id
DocumentRoot /var/www/website.go.id
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
SSLEngine on
SSLCertificateFile /home/website.go.id/ssl/website.go.id.crt
SSLCertificateKeyFile /home/ssl/website.go.id.key
SSLCertificateChainFile /home/simaled/ssl/DigiCertCA.crt
<FilesMatch "\.(cgi|shtml|phtml|php)$">
SSLOptions +StdEnvVars
</FilesMatch>
<Directory "/var/www/website.go.id">
Options Indexes FollowSymLinks ExecCGI Includes
AllowOverride None
Require all granted
</Directory>
<Directory /usr/lib/cgi-bin>
SSLOptions +StdEnvVars
</Directory>
</VirtualHost>
I know you all probably wonder why i set the AllowOverride None . that's because when i set the AllowOverride to all all my pages become 403 Forbidden.
this is my .htacces code :
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^lib/(.*) /wp-includes/$1?FJN_hide_my_wp=1234 [QSA,L]
RewriteRule ^user_submit /wp-comments-post.php?FJN_hide_my_wp=1234 [QSA,L]
RewriteRule ^wp-content/themes/jdih-child/screenshot\.png|readme\.html|license\.txt|wp-content/debug\.log|wp-includes/$ /nothing_404_404?FJN_hide_my_wp=1234 [QSA,L]
RewriteRule ^(index\.php|wp-comments-post\.php|wp-includes/js/tinymce/wp-tinymce\.php|xmlrpc\.php|wp-cron\.php|wp-admin/upgrade\.php|php-info\.php|sync-jdihn\.php|wp-login\.php|index\.php|wp-admin/|wp-content/plugins/)(.*) $1$2?FJN_hide_my_wp=1234 [QSA,L]
RewriteRule ^(.*)\.php(.*) /nothing_404_404?FJN_hide_my_wp=1234 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I have installed my new website on an AWS EC2 instance and have an elastic IP. I have already enabled HTTPS for my site. At present, the domain loads with the website without any issue, but the IP points to the Apache default page. I followed several tutorials to point the IP address back to the HTTPS version of my site. But it's not working. But if I use https://xx.xx.xx.xx I get a "Your connection is not private" warning.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteCond %{REMOTE_ADDR} ^xx\.xx\.xx\.xx$
RewriteRule ^(.*)$ https://mynewwebsite.com/$1 [L,R=301]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Vhost:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin#mynewwebsite.com
ServerName mynewwebsite.com
ServerAlias www.mynewwebsite.com
DocumentRoot /var/www/html/wordpress
ErrorLog ${APACHE_LOG_DIR}/mynewwebsite.com_error.log
CustomLog ${APACHE_LOG_DIR}/mynewwebsite.com_access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mynewwebsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mynewwebsite.com/privkey.pem
</VirtualHost>
</IfModule>
You have to define two VirtualHost with 443 ports.
One of this contains the same configuration for your application:
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin#mynewwebsite.com
ServerName mynewwebsite.com
ServerAlias www.mynewwebsite.com
DocumentRoot /var/www/html/wordpress
ErrorLog ${APACHE_LOG_DIR}/mynewwebsite.com_error.log
CustomLog ${APACHE_LOG_DIR}/mynewwebsite.com_access.log combined
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/mynewwebsite.com/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/mynewwebsite.com/privkey.pem
</VirtualHost>
</IfModule>
One for redirect without ServerName and ServerAlias equal to wildcard (*).
<IfModule mod_ssl.c>
<VirtualHost *:443>
ServerAdmin admin#mynewwebsite.com
ServerAlias *
DocumentRoot /var/www/html/
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule ^(.*)$ https://mynewwebsite.com/$1 [L,R=301]
</IfModule>
</VirtualHost>
</IfModule>
This prevent to get the default page even if the user try to make a request with a FQDN different from your configuration.
Important!: You have to respect the order of configuration.
Salvo.
The problem solved when I replaced ServerName with my IP instead of my server FQDN. I assume this method only works, if you have added the server and domain in /etc/hosts, which I have already added.
<VirtualHost *:80>
ServerAdmin admin#mynewwebsite.com
ServerName xx.xx.xx.xx <------------------- IP
ServerAlias www.mynewwebsite.com
DocumentRoot /var/www/html/wordpress
ErrorLog ${APACHE_LOG_DIR}/mynewwebsite.com_error.log
CustomLog ${APACHE_LOG_DIR}/mynewwebsite.com_access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =mynewwebsite.com [OR]
RewriteCond %{SERVER_NAME} =www.mynewwebsite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
<VirtualHost *:80>
ServerAdmin admin#mynewwebsite.com
ServerName mynewwebsite.com <------------------- Domain
ServerAlias www.mynewwebsite.com
DocumentRoot /var/www/html/wordpress
ErrorLog ${APACHE_LOG_DIR}/mynewwebsite.com_error.log
CustomLog ${APACHE_LOG_DIR}/mynewwebsite.com_access.log combined
RewriteEngine on
RewriteCond %{SERVER_NAME} =mynewwebsite.com [OR]
RewriteCond %{SERVER_NAME} =www.mynewwebsite.com
RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Hi I am having a little problem after using permalinks wordpress, the https version of the site shows the Apache start page. On the http version, the site and all permalinks work fine. I also want to say that without using permalinks, the site on http and https works well. I am using CentOS 8
My .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
My httpd.conf
IncludeOptional conf.d/*.conf
<VirtualHost *:443>
DocumentRoot "/var/www/wordpress"
ServerAlias www.example.com
<Directory "/var/www/wordpress">
allow from all
Options None
Require all granted
</Directory>
SSLEngine on
SSLProtocol +TLSv1.1 +TLSv1.2
SSLCertificateFile /var/ssls/cazzy_store.crt
SSLCertificateKeyFile /var/ssls/cazzy.key
SSLCACertificateFile /var/ssls/cazzy_store.ca-bundle
</VirtualHost>
I tried adding AllowOverride All ”to the <Directory” in my httpd.conf file but it didn't help
I solved the problem by adding this to my .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymLinks
</IfModule>
Since I've setup a wildcard VirtualHost my htaccess files does not work anymore
The http-vhosts.conf
NameVirtualHost *
<VirtualHost *:80>
ServerName default.dev
VirtualDocumentRoot /Users/[UserName]/Sites/%-2
<Directory /Users/[UserName]/Sites/%-2>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
the .htaccess (WordPress default)
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I can access http://wordpress.dev and also the backend but not a page like http://wordpress.dev/page (causes a 404 error).
I can set the permalink structure to default but I would like to have "nice URLs"
I'm on a local development environment on Mac OS X 10.10 with Apache 2.4
Change your VirtualHost definition to:
<VirtualHost *:80>
ServerName default.dev
VirtualDocumentRoot /Users/[UserName]/Sites/%-2
<Directory /Users/[UserName]/Sites>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
i.e, root the directory definition to Sites, not to the virtual directory.