Wordpress permalinks fails with virtualhost - wordpress

I have a wordpress blog in a local server: /var/www/html/blog
(In the root dir '/var/www/html' there are other pages i shouldn't move, so I cant't put the wordpress blog in the root)
I bought a domain name and I've assigned it to this blog with a virtualhost. Then I activated the permalinks in the wordpress blog.
The problem is that when I go to mydomain/index.php or mydomain/, it shows a "Apache 2 Test Page" and in the apache error log it writes this message:
Options FollowSymLinks or SymLinksIfOwnerMatch is off which implies that RewriteRule directive is forbidden: /var/www/html/blog/
If I go to mydomain/wp-login.php, it's right. If I go to mydomain/section/blabla/, it's right. But the index page fails.
If I comment the .htaccess file I have put in the wordpress blog, the index page works, but pages like mydomain/section/blabla/ doesn't.
This is my virtualhost config code:
<VirtualHost *:80>
ServerAdmin ...Mymail...
DocumentRoot /var/www/html/blog
ServerName ...mydomain...
</Virtualhost>
And this is my .htaccess in the wordpress directory:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

Solved.
Finally I moved the blog files to the root apache directory. Then I removed the virtualhost and I created a redirection rule: mydomain/ -> mydomain/index.php
And it works.

Try putting
Options +FollowSymLinks
at the top of your .htaccess file

Related

Can't access wp-admin with virtual host

I have a problem with my WordPress website. It runs perfectly on localhost but when I try to add a virtual host to it, I can't access the admin panel. I am using xampp.
I have tried to access it by typing http://localhost/commerce/wp-admin and me.commerce.loc/wp-admin in the search bar but none of those work. Both return Oops! That page can’t be found..
Here is the code I wrote in my httpd-vhosts.conf file:
<VirtualHost *:80>
DocumentRoot "C:/xampp/htdocs/commerce"
ServerName webmaster.loc
</VirtualHost>
This is my .htaccess file:
# 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
My code in hosts file:
# localhost name resolution is handled within DNS itself.
127.0.0.1 localhost
::1 localhost
127.0.0.1 me.commerce.loc
You can also override siteurl and homeurl in wp-config.php.
define('WP_HOME','http://me.commerce.loc');
define('WP_SITEURL','http://me.commerce.loc');
Please this post for more detail https://help.dreamhost.com/hc/en-us/articles/214580498-How-do-I-change-the-WordPress-Site-URL-
I have done some research and it turns out I had to change siteurl and home fields in my wp_options table. After setting them to my v-host address it works perfectly.

How to add WordPress' htaccess configurations into VirtualHost conf

I put WordPress' configuration into my VirtualHost directive, it looks like this:
<VirtualHost *:80>
ServerName www.example.com
ServerAlias example.com
DocumentRoot /var/www/html
<Directory />
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
# add a trailing slash to /wp-admin
RewriteRule ^wp-admin$ wp-admin/ [R=301,L]
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^(wp-(content|admin|includes).*) $1 [L]
RewriteRule ^(.*\.php)$ $1 [L]
RewriteRule . index.php [L]
</Directory>
</VirtualHost>
When I put WordPress' configuration inside VirtualHost's root directory like above, the permalink and sub domain won't work.
But when I put WordPress' configuration inside the /etc/httpd/conf/httpd.conf root directory which is /var/www/html (as you can see it is the same root as Virtual host), then subdomain and permalinks are fine, I don't get it?
The reason I don't want to put WordPress' configuration in httpd.conf is because I want to make another site but it's not multisite, so I have to enter another WordPress' configuration on it.
I IncludeOptional the virtual host conf file at the very bottom of httpd.conf
I use CentOS 7
Apache 2.4
Wordpress 4.5.3
Mod rewrite included
After few hours it seems another rewrite rule that came above the IncludeOptional path/to/virtualhost/*.conf in httpd.conf had interfere Wordpress' configuration.
To troubleshoot most common permalinks or subdomains problem in wordpress is always check your rewrite rules and make sure the Wordpress rule (that one for the .htaccess) is always on top of the others.

WordPress index page is giving 404

My WordPress installation is in a different folder from my main site:
/var/www/html/wordpress <= WP installation
/var/www/html/main-site <= main site
I would like to have WP display when someone visits /blog from my main site:
http://www.main-site.com/blog (Note: main-site is used as a generic placeholder for the real site because it is not launched yet)
I have set up an alias in my httpd conf file:
Alias /blog /var/www/html/wordpress
<Directory /var/www/html/main-site>
DirectoryIndex index.php
Options -MultiViews
AllowOverride All
order allow,deny
allow from all
</Directory>
I have the following as my .htaccess file for WP:
<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>
I get a 404 when I visit http://www.main-site.com/blog but when I visit http://www.main-site.com/wp-admin/index.php, it works (but I get a 404 if I visit /admin). Visiting the sample blog post and sample page also works for me.
http://www.main-site.com/blog/hello-world/
http://www.main-site.com/blog/sample-page/
It looks like rewrite is working but my /blog index page doesn't work.
Any suggestions would be greatly appreciated.
Thanks,
Allen
Finally figured this one out! It turns out that Passenger was enabled and I had to disable it.
Alias /blog /var/www/html/wordpress
<Directory /var/www/html/main-site>
PassengerEnabled off
DirectoryIndex index.php
Options -MultiViews
AllowOverride All
order allow,deny
allow from all
</Directory>

Changing .htaccess file in order to allow subdomains

I'm hosting a Wordpress page in my domain and I would like to create a subdomain in order to host also a wiki page.
Example:
www.foowordpress.com -> Points to a Wordpress blog
wiki.foowordpress.com -> It should point to a Media Wiki page
It seems that the .htaccess generated by Wordpress redirects all subdomains to the Wordpress index page.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Could someone suggest how to change this .htaccess file in order not to redirect the wiki subdomain?
I've already configured my DNS manager and my VirtualHost for creating this subdomain.
As it turns out, I had not configured properly the VirtualHost file, there was nothing wrong with the .htaccess file.
Here is my VirtualHost file for the subdomain in case anyone finds it useful:
<VirtualHost *:80>
# Admin email, Server Name (domain name), and any aliases
ServerAdmin webmaster#foo.com
ServerName www.wiki.foo.com
ServerAlias wiki.foo.com
# Index file and Document Root (where the public files are located)
DirectoryIndex index.html index.php
DocumentRoot /var/www/wiki.foo.com/
# Log file locations LogLevel warn ErrorLog
/var/log/apache2/wiki.foo.com/error.log CustomLog
/var/log/apache2/wiki.foo.com/access.log combined
</VirtualHost>

wordpress multisite with sub-domain pretty permalinks

i am trying to set up a wordpress (3.4.2) multisite. The current site already has the following apache rules applied, which i do not have the permissions to edit
<VirtualHost xx.xx.xx.xxx:80>
ServerName foo.example.nl
ServerAlias www.foo.example.nl
DocumentRoot /web/sites/example.nl/foo/www
RewriteEngine On
<Location />
Allow from all
</Location>
</VirtualHost>
this works fine however i found that trying to set up permalinks with 'Post name' options always gives me a 404 redirect.
http://foo.example.nl/post1 = 404 Not Found
at the moment i have un-installed multisite just to try and get the pretty urls working with the sub-domain but after trying lots of different variations of my .htaccess but nothing seems to be working. here is the current .htaccess wordpress generates:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Unfortunately you are probably limited from using .htaccess to configure the RewriteRules. If you referent to the Wordpress documentation on Using "Pretty" Permalinks you will see that you need to have Options FollowSymLinks enabled as well as AllowOverride Fileinfo or AllowOverride All to be able to use the pretty URL configuration in .htaccess. Since these don't seem to be set your <VirtualHost> it is likely your problem, since they are typically not set at a higher level in the Apache configuration.

Resources