Can't access wp-admin with virtual host - wordpress

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.

Related

How to remove rewrite an URL on Wordpress/Apache2 based on a specific address

I am trying to configure a wordpress site running on Apache2 but I am having some problems.
My Wordpress version is 5.9.1 and Apache 2.4.41 running on Ubuntu Server 20.04.
Wordpress Permanent Link Configuration is: https://domain-name/index.php/%postname%/
In this configuration almost everything is working fine, the index.php appears in the URL but my first problem is when a user try to access a course page (this is a LMS platform).
The URL changes to https://domain-name/course/%postname%/.
If manually I insert index.php to the URL https://domain-name/index.php/course/%postname%/
the content works fine.
I already configure the default site.
/etc/apache2/sites-available/000-default.conf:
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>*
/var/www/html/.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>
When user try to access the URL https://domain-name/course/%postname%/,
is it possible to rewrite the URL changing to https://domain-name/index.php/course/%postname%/?

Wordpress permalinks fails with virtualhost

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

WordPress Permalinks Doesn't Work

I'm trying to create pretty permalinks through WordPress and I keep getting 404 errors. I've scoured the internet and I can't find any solution. I've never had an issue with this before so I'm totally stumped.
The hosting is under Network Solutions. I called them and they sent me this link: http://www.networksolutions.com/support/PHP-ini-for-UNIX-Shared-Hosting-FAQ
What I've tried:
1. Adding a php.ini file to my root.
2. Adding a php.ini file to the cgi-bin folder
3. Adding the rewrite commands to my .htaccess file (which is located in the root of my website).
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /stage/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /stage/index.php [L]
</IfModule>
# END WordPress
After each of these, I've resaved the permalink settings to flush the changes.
I still keep getting a 404 error.
I had the same problem on an Ubuntu 14.04 server which is running as a staging server.
In this case the rewrite module was not enabled by default; so Pagination and "non-ugly" Permalinks were not working (as they rely on .htaccess rewrite rules to work).
You have to edit the Apache conf file (in Ubuntu 14.04: /etc/apache2/apache2.conf) and change the AllowOverride setting from None to FileInfo
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride FileInfo
Require all granted
</Directory>
You may need to enable the Rewrite module:
sudo a2enmod rewrite
and to complete you will need to restart
sudo service apache2 restart
That's been bugging me for a month or so, now, so kudos to the solution found:
https://askubuntu.com/questions/48362/how-to-enable-mod-rewrite-in-apache
Login to your server using FTP, and modify the .htaccess file which is located in the same location where folders like /wp-content/ and /wp-includes/ are located. The easiest thing you can do is to temporarily make the file writeable by changing the permissions to 666. Then repeat the original solution. Don’t forget to change the permissions back to 660. You can also manually add this code in your .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
Another solution: Put index.php at the start of your custom permalink structure, for example:
/index.php/%year%/%monthnum%/%day%/%postname%/

Wordpress subpages throwing 404 after restoring

I am a newbie to wordpress though I have programming background. Recently I moved a wordpress website from justhost shared server to a
linode vps server (Ubuntu OS). I did following steps to achieve it
Set up apache2 server on vps
Set up virtualhost on vps
Created a directory under /var/www/ftpadmin/www/
Note. ftpadmin was created to restrict ftp access to files under that folder. I could make work static html and php websites after doing so.
Took backup of database and wp-content folder from justhost server of respective wordpress website.
Now on vps, at specified location above, first I download latest version of wordpress and unzipped the files.
Created database of same name at mysql and then imported original to the same database.
replaced new wp-content folder with the one from original one.
I was following instructions on https://www.digitalocean.com/community/articles/how-to-set-up-multiple-wordpress-sites-on-a-single-ubuntu-vps.
restarted apache server. Now I could access the home page.
I corrected the database values for wordpress url and site address url to new one at older location and reloaded database which helped me access dashboard and login pages also.
I created a .htaccess file like mentioned in http://ahsan.vimmaniac.com/blog/enabling-wordpress-permalinks-on-ubuntu/.
I also changed "AllowOveride" under both section in /etc/apache2/sites-available/ as
<Directory />
Options FollowSymLinks
AllowOverride all
</Directory>
<Directory /var/www/ftpadmin/www/domainname>
RewriteEngine On
Options Indexes FollowSymLinks MultiViews
AllowOverride FileInfo
Order allow,deny
allow from all
</Directory>
restarted service apache once again.
One final point, I am using a custom template and so I have a header.php and header-sub.php file for homepage and navigation.
Now here is the problem. When I click on any submenu I get "Internal Server Error".
If I remove .htaccess and reload apache server. Now I get 404 error while clicking on and submenu.
Any help is highly appreciated? I looked at various sites to collate these many steps and execute. I have no Idea what I should do to correct this situation. But when I go dashboard -> All pages, I can find all pages existing there with contents.
Thanks in Advance
Fayaz
EDIT
Added .htaccess file from comment:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /wordpress/ (wordpress replaced with my domainname, bottom also)
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
I got the above problem fixed by just replacing
RewriteBase /wordpress/ as "RewriteBase /"
and
RewriteRule ./wordpress/index.php [L} as "RewriteRule . /index.php [L]".
in .htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Finally fixed this errow after browsing for a couple of hours and trying many options.
In this block in your Apache httpd.conf file, (located in my CentOS instance at $ sudo vi /etc/httpd/conf/httpd.conf)
#
# AllowOverride controls what directives may be placed in .htaccess files.
# It can be "All", "None", or any combination of the keywords:
# Options FileInfo AuthConfig Limit
#
AllowOverride None
change AllowOverride None to AllowOverride All.
Src: https://wordpress.org/support/topic/secondary-or-child-pages-returning-a-404-error-after-wp-34-update#post-3830892

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>

Resources