I run a wordpress on AWS, the public domain assigned by AWS is "ec2-23-23-124-60.compute-1.amazonaws.com", and the virtualhost setting is as following:
<VirtualHost *:80>
ServerName remykits.com
DirectoryIndex index.php
DocumentRoot "/home/mysite/sites/blog"
LogLevel info
ErrorLog /var/www/vhosts/domain.com/log/error.log
CustomLog /var/www/vhosts/domain.com/log/access.log combined
</VirtualHost>
but when I click a link in my blog, the url changes to "http://ec2-23-23-124-60.compute-1.amazonaws.com/", I have no idea how to solve it.
I think this more of a Wordpress issue than an Apache one. Go into your Admin panel, go to Options and change your Site URL to point to remykits.com. Your links should now use this as the base_url for the site.
If your Apache configuration was incorrect, your Wordpress installation would most likely not even render. Your ServerName is correct, which is the most important thing.
This needs to be fixed with Wordpress. Wordpress generates links and URLs on your page based on the domain name in the database. Which seems to be ec2-23-23-124-60.compute-1.amazonaws.com. This usually happens when someone installs Wordpress by going to that domain name, rather than your actual domain name (remykits.com). People usually do this because they want to install Wordpress on the server, but don't want to wait for the domain name to point to the server IP while DNS propagates.
Wordpress has a well written Codex page on how to change the domain your Wordpress installation uses. While the codex article goes into detail on how to make these changes manually, the following is all you really need to do.
On the Settings->General screen in a single site installation of WordPress, there are two >fields named "WordPress address (URL)" and "Site address (URL)". These are also known as >the "Home" and "Site URL" settings. They are important settings, since they control where >WordPress thinks your site is located. They control the display of the URL in the admin >section of your page as well as the front end, and are used throughout the WordPress code.
The "Home" setting is the address you want people to type in their browser to reach >your WordPress blog.
The "Site URL" setting is the address where your WordPress core files reside.
Note: Both settings should include the http:// part and should not have a slash "/" at the >end.
Wordpress Codex - Changing The Site URL
Related
I set up apache2 server. The following is in /etc/apache2/sites-enabled/default-ssl.conf.
<IfModule mod_ssl.c>
<VirtualHost _default_:443>
ServerAdmin webmaster#localhost
DocumentRoot /var/www/html
...
If I visit https://www.example.com/index.html it displays the content of /var/www/html/index.html file as expected. However, if I just visit https://www.example.com, it redirects to https://www.example.com/blog. I can't find anything in /etc/apache2 directory that contains "blog" at all.
I did try to put a wordpress "blog" folder inside /var/www/html before and have a "blog" database in mysql. But I didn't really get it to work and tried to abandon it. Now it appears I am stuck with it and I can't figure out where it is enabled. I also noticed, if I visit http://www.example.com (not https) it doesn't redirect to /blog but displays index.html content.
Appreciate if anyone can explain how/why apache2 decides to redirect https://www.example.com to https://www.example.com/blog. Thanks.
Login to your WordPress Dashboard, and go to Settings, then General. There will be two entries: WordPress Address and Site Address. It's likely that one or both entries will have "https://www.example.com/blog" as the value. Update these URLs and click on Save Changes at the bottom of the page.
However, if you cannot access the WordPress Dashboard, you'll have to review the database. Check your WordPress database, specifically the "wp_options" table; name varies by prefix, but "wp_" is default. In it, there are 2 entries which tell the WordPress site where it is hosted. Here is the MySQL query you can run to see what it says:
SELECT * FROM wp_options WHERE option_name IN ('home', 'siteurl');
You can update the fields with this query:
UPDATE wp_options SET option_value = 'https://www.example.com/' WHERE option_name IN ('home', 'siteurl') LIMIT 2;
The home (WordPress Address) vs siteurl (Site Address) entries differ in that the home entry is where your site can be reached, and siteurl is the URL of where the site content is located (DocumentRoot). Given your situation, it would appear that your home will have "/blog" and your siteurl will have the correct URL. Here is the WordPress documentation regarding the siteurl entry.
As for http vs https, that would depend on your sites-available configuration, but you can also force https with your .htaccess file, and both home and siteurl URL entries.
EDIT: as a quick fix, you can also update your wp-config.php file for the respective entries, but the better, permanent solution is to use the WordPress Dashboard (or manually updating the database for the same fields).
Background
As someone who develops multiple websites I wanted to be able to serve each site from within its respective project folder in the filesystem, instead of serving them all under the htdocs directory.
So I moved my wordpress folder (whose site was usually accessed via localhost/wordpress) to my project directory, and followed the instructions in this answer to set up a virtual host with a DocumentRoot and Directory that matches the new location of the wordpress folder. This is the whole (uncommented portion) of my httpd-vhosts.conf:
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot "D:\Users\User\Documents\Projects\Websites\My New Project\wordpress"
ServerName localhost.irm
<Directory "D:\Users\User\Documents\Projects\Websites\My New Project\wordpress">
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
The Problem
The homepage can now be found at localhost.irm, but it's text-only, with no styles or images, and clicking on any page takes me to an "Object not found!" XAMPP page.
What I've Tried
Accessed the database with PHPMyAdmin, changing siteurl and home in the wp_options table to reflect the new domain
Used the WP-CLI tool to search-and-replace all database instances of the old domain with the new one
Unfortunately none of these solved the problem.
This seemed to be primarily caused by two problems:
The Site Ground Optimiser plugin from my live site that I wasn't even aware was activated on my local site. Deactivating using wp plugin deactivate sg-cachepress (the WP-CLI tool) solved that.
The following line in my .htaccess file, at the root of my Wordpress site:
RewriteBase /wordpress/
I assume it must have been necessary to add for my previous setup and I'd since forgotten about it. Either way, removing/commenting the line out entirely seems to have solved the rest of the problem.
I'm now able to access my website with all styles and images, just like I was before, with the advantage that my files are now being served from my project folder itself instead of from XAMPP\htdocs.
I've a WordPress site which needs to be accessible via both public domain name and IP address as well. It needs to behave exactly the same when accessed from any.
I tried adding IP as server alias bit that seem to work for home page only.
ServerName site.local
ServerAlias www.site.local
ServerAlias 127.0.0.10
When traversing pages, it redirects to server name instead of server alias I added.
Since WP stores site url and home url in database itself, I think it priorities it.
Is there any way I can make this thing happen.
You could set WP_HOME and WP_SITEURL constants in wp-config.php based on what $_SERVER["HTTP_HOST"] is.
That will take care of a lot, but if you have hardcoded links to http://example.com/mypage/, those will not be rewritten to http://10.10.10.10/ when accessed via IP. If you require that, you'll probably have to use an output handler that changes the output after it has been generated.
I am currently working on a wordpress multisite project. I have set up a working environment in localhost. In the main menu there is a links to home, so is in subdirectory sites. Now my problem is everything works find in testing server environments as the main site URL is myhost/xx/wordpress_site and sub directory sites are like myhost/xx/wordpress_site/sub_dir. In wordpress Appearance->menu you can only give a static url in the link URL field. What I am looking for is to give a method like site_url().”/sub_dir” in that field so I don’t have to manually alter all the site home URLs when I upload the site to it’s destination domain. Which can be any form?
Any simple solution regarding this problem its greatly appreciated.
Thanks a lot.
I would not recommend to change anything on wordpress code or site url configuration.
because when you will go to production you will have to change it back again.
It will be the best if you will setup the same site configuration on your localhost, you can use the following configuration for your apache server and host file so you will be able to
access your local site by your actual domain.
This way your settings will remain the same and all site links will be the same.
(rename mysite to your site url)
how to change host file:
http://www.howtogeek.com/howto/27350/beginner-geek-how-to-edit-your-hosts-file/
how to add virtual host apache:
http://httpd.apache.org/docs/current/vhosts/examples.html
Apache configuration:
<VirtualHost mysite.com:80>
ServerName mysite.com
DocumentRoot /var/www/mysite
<Directory /var/www/mysite>
Options FollowSymLinks
AllowOverride All
</Directory>
</VirtualHost>
host file configuration:
127.0.0.1 mysite.com
restart apache and you will be able to work on localhost like it is the productin server.
* Remove the following when you want to access the real server.
This question has been asked amply all over the internet and on SO -- The available answers are obscured by specific details about everyone's particular installation. Hopefully this question will help everyone, including me, understand this better.
My question is "How should we configure the Apache .conf file to handle multiple domains?"
(I know the answer "depends". Hopefully, 80% of the people out there are going to have a basic setup at first and then make it more complex later.) I hope that's a good assumption.
I'm comparing Magento's install to Wordpress. Under Wordpress, the "best way" to install it seems to be to put the whole core into a folder called /wordpress. Then, using Apache rewrite rules and permalinks, obscure the /wordpress folder. In a multi-domain situation, the Wordpress core smartly handles the whole process for you without much modification of the .htaccess files. Further, whatever modifications do need to be made, Wordpress can do it for you - or a plugin can. Gosh, I wish Magento was as easy to install as Wordpress. But it's not. (yet!)
Under Magento, the term "store" is very misleading when we think about URLs. So let's ignore it for now and just worry about the lowest level -- the "Store View". In my case, I have the following:
Main Web Site -> Main Web Site Store -> Default Store View
www.site1.com -> Main Store -> site1_english
www.site2.com -> Main Store -> site2_english
The first column is the domain.
The second column is the store --
misleading title for this discussion.
The last column is the "Store View".
As for where to physically place the files. Most people, including me, want to leave the Magento core alone. No changes at all. So we put that into the htdocs root as follows:
/var/www/html/magento
This is where everyone gets confused I think. The Linux distros are not consistent about where this location is. And worse, lots of people are trying to do this on an economical hosting account. I'm using EC2 myself. Ignoring all that... Stick /magento in your document root. The next thing you might add is a /wordpress folder. Yay. Do it later.
In my apache config, I have it setup like this:
# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80
<VirtualHost *:80>
ServerName site1.com
ServerAlias www.site1.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento/>
AllowOverride All
</Directory>
# Other directives here
SetEnv MAGE_RUN_CODE "site1"
SetEnv MAGE_RUN_TYPE "website"
</VirtualHost>
<VirtualHost *:80>
ServerName site2.com
ServerAlias www.site2.com
DocumentRoot /var/www/html/magento
<Directory /var/www/html/magento/>
AllowOverride All
</Directory>
# Other directives here
SetEnv MAGE_RUN_CODE "base"
SetEnv MAGE_RUN_TYPE "site2_en"
</VirtualHost>
<VirtualHost *:80>
DocumentRoot /var/www/html/nowhere
</VirtualHost>
The /nowhere folder has an index.html that says "no where".
The situation that I'm seeing is as such:
Navigate to www.site1.com -> Magento redirects to the Default Store View (on the IP address)
Navigate to www.site2.com -> Magento redirects to the Default Store View (on the IP address)
Navigate to the IP address of my server -> Magento displays the Default Store View
The Default Store View's BASE URL is http://my.ip.add.ress
Here are my questions:
What are we supposed to put in MAGE_RUN_CODE and MAGE_RUN_TYPE? Some sites say "website", some say "store". What is supposed to go in there?
Why don't I ever get to my nowhere site?
Why does the www.site1.com keep redirecting to the Default Store View?
Some of the documentation out there talks about creating dedicated folder or copying around index.php or .htaccess. Or making our own .htaccess. In this article, I selected the Apache config file.
Why won't that work right?
Why does the www.site1.com keep redirecting to the Default Store View?
Go to
System->Configuration->General->Web
There you should find Base secure and Base unsecure URL for you store. Moreover to the upper left corner you should see the scope of your settings. So for each store view you should change(if possible) URL of your store view.
What are we supposed to put in MAGE_RUN_CODE and MAGE_RUN_TYPE? Some sites say "website", some say "store". What is supposed to go in there?
If I don't mistake in code you specify the code of the "object" you want to launch, and in type you specify the type of this object - store or website. But this is not 100% info.