I have a bitnami apache2 wordpress site.
my htdocs is in the /opt/bitnami/apps/wordpress/htdocs directory and everything inside that has been moved to a directory called blogs which is in the same htdocs as below:
/opt/bitnami/apps/wordpress/htdocs/
/blogs
- contents
And now when I access blog.mydomain.com it gives the File permission error as below:
Forbidden You don't have permission to access this resource.
But when I access blog.mydomain.com/blogs I can see the content.
So, how I can redirect from blog.mydomain.com to blog.mydomain.com/blogs when someone hits blog.mydomain.com
Bitnami developer here!
If you don't plan to use the main domain as a double website setup, you could simply perform a redirection using the RedirectMatch directive in your VirtualHost.
If you use the original VirtualHost setup of the instance, add the following lines to /opt/bitnami/apache2/conf/bitnami/bitnami.conf:
...
<VirtualHost _default_:80>
+ RedirectMatch ^/$ /blog/
DocumentRoot "/opt/bitnami/apache2/htdocs"
<Directory "/opt/bitnami/apache2/htdocs">
...
</VirtualHost>
...
<VirtualHost _default_:443>
+ RedirectMatch ^/$ /blog/
DocumentRoot "/opt/bitnami/apache2/htdocs"
SSLEngine on
...
</VirtualHost>
...
Explanation: When the current URL matches the root of your domain, http(s)://YOUR-DOMAIN/, the server will redirect to the second argument of the directive, http(s)://YOUR-DOMAIN/blog
If are using another VirtualHost setup, just place this modification there.
Related
I have a website, with some content in the root folder.
I then have a Wordpress site in a subfolder of a subdomain. So for example the url to the Wordpress 'contact' page looks like this.
subdomain.mywebsite.com/subfolder/contact/
Is there a way to get this Wordpress site to act as the root of the website without moving files around? Either through an htaccess file or any other method?
It would be important that the user doesn't know they are in a subdomain/subfolder, so for the contact page of the wordpress site the url bar would have to look something like:
www.mywebsite.com/contact/
Would really appreciate any help.
You can do that in the vhost entry of your webserver.
Example main entry:
<VirtualHost *:80>
ServerAdmin xxx#xxx.com
DocumentRoot "c:/Users/xxx/Documents/www/"
ServerName xxx.com
ErrorLog "logs/xxx.error.log"
CustomLog "logs/xxx.access.log" common
</VirtualHost>
Example subdomain entry:
<VirtualHost *:80>
ServerAdmin xxx#xxx.com
DocumentRoot "c:/Users/xxx/Documents/www/subfolder"
ServerName subdomain.xxx.com
ErrorLog "logs/subdomain.xxx.error.log"
CustomLog "logs/subdomain.xxx.access.log" common
</VirtualHost>
RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/subfolder/$1 -f
RewriteRule ^([^/]+)/?$ /subfolder/$1 [L]
This will internally map /file/ to /subfolder/file if the requested file exists in /subfolder.
I have a blog on wordpress, for example www/blog.com - folder
and my site example.com, www/example.com - folder.
I try integrate worpress with my site. example.com/blog - must go to wordpress index page, and example.com/blog/post_name must go to wordpress post.
apache conf
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/example.com
ServerAlias www.example.com
Alias /blog /var/www/blog.com
<Location /blog>
</Location>
</VirtualHost>
<Directory /var/www/example.com>
#code
</Directory>
<Directory /var/www/blog.com>
#code
</Directory>
In worpress admin panel i change:
WordPress Address (URL) to example.com/blog
Site Address (URL) to example.com
Permalink Settings to /blog/%postname%/
When i go to example.com/blog it work fine, but when i type
example.com/blog/post_name i have 404 error.
Edit:
request example.com/blog go to wordpress directory, but example.com/blog/post_name go to example.com index.php
check out this wordpress.org article. it will help you ensure that you have mod_rewrite enabled, along with inserting the AllowOverride FileInfo directive that I can already see you're missing within your VirtualHost. Don't forget to read on about the .htaccess file for your /blog (/var/www/blog.com) directory. You'll want to make sure your RewriteBase is set to /blog
I'm trying to setup my site to use www only, and non-www should be permanently redirected to www. This answer suggested using two virtual hosts, however it causes me to go into a redirect loop.
Here's the configuration for the site:
<VirtualHost *:80>
ServerName www.mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/me/sites/mydomain.com/htdocs
# Log file locations
LogLevel warn
ErrorLog /home/me/sites/mydomain.com/logs/error.log
CustomLog /home/me/sites/mydomain.com/logs/access.log combined
</VirtualHost>
<VirtualHost *:80>
ServerName mydomain.com
Redirect permanent / http://www.mydomain.com/
</VirtualHost>
When I visit the non-www version of the site it successfully redirects to the www version, however Chrome then tells me that there was a redirect loop.
At first I thought it could be .htaccess in my document root however after removing that file it still happens. It's just a simple Wordpress site.
Can anyone see something wrong with the config that would cause this to happen? If not, how can I narrow down the cause?
You don't need a separate VirtualHost entry for non-www and use ServerAlias instead. Also to redirect to www just use a rule like this:
<VirtualHost *:80>
ServerName www.mydomain.com
ServerAlias mydomain.com
DirectoryIndex index.html index.php
DocumentRoot /home/me/sites/mydomain.com/htdocs
# Log file locations
LogLevel warn
ErrorLog /home/me/sites/mydomain.com/logs/error.log
CustomLog /home/me/sites/mydomain.com/logs/access.log combined
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</VirtualHost>
I put my plone site on a remote sever. I configured the virtual host.
When I get to the default page, it just shows as plain html format. No CSS no style.
My rewrite rule is:
^/(.*) http://localhost:8085/VirtualHostBase/http/interoptest-vlab.drimm.u-bordeaux1.fr:80/VirtualHostRoot/$1 [P,L]
The site is
http://interoptest-vlab.drimm.u-bordeaux1.fr/
you can go and have a look.
The rest is like this.
<VirtualHost *:80>
ServerName interoptest-vlab.drimm.u-bordeaux1.fr
ServerAlias www.interop-vlab.eu
ServerSignature On
ProxyVia On
# prevent your web server from being used as global HTTP proxy
<LocationMatch "^[^/]">
Deny from all
</LocationMatch>
<Proxy *>
Order deny,allow
Allow from all
</Proxy>
RewriteEngine on
RewriteLogLevel 1
Rewritelog /var/log/apache2/plone4_rewrite_log
RewriteRule ^($|/.*) \
http://127.0.0.1:8085/VirtualHostBase/\
http/%{SERVER_NAME}:80/VirtualHostRoot$1 [L,P]
</VirtualHost>
You want to use the excellent RewriteRule Witch to generate your VHM rewriting configurations.
For your settings, the witch recommends you use:
RewriteRule ^($|/.*) \
http://127.0.0.1:8085/VirtualHostBase/\
http/%{SERVER_NAME}:80/VirtualHostRoot$1 [L,P]
This differs from yours in that the root is handled better, and the server name is auto-included from the browser headers, ensuring that you always use the correct server name.
However, your site is serving just the homepage, even a obvious 404 not found response results in the homepage. Something is rewriting your paths to discard all path information, perhaps before the VHM proxy rewrite rule is executed.
I have my website and WordPress installed on a Linode server running Ubuntu.
The directories are:
~/public_html - Website
~/public_blog - WordPress installation
My DNS and site config is set up so that:
hashbang0.com - Points to website in ~/public_html
blog.hashbang0.com - Points to WordPress install in ~/public_blog
Site config as follows:
<VirtualHost 123.456.789.000:80>
ServerAdmin user#gmail.com
ServerName hashbang0.com
ServerAlias www.hashbang0.com
DocumentRoot /home/user/public_html/
ErrorLog /home/user/log/error.log
CustomLog /home/user/log/access.log combined
</VirtualHost>
<VirtualHost 123.456.789.000:80>
ServerAdmin user#gmail.com
ServerName blog.user.com
ServerAlias blog.user.com
DocumentRoot /home/user/public_blog/
ErrorLog /home/hashbang0/log/blog_error.log
CustomLog /home/hashbang0/log/blog_access.log combined
</VirtualHost>
Now, I have had enough of tinkering with PHP, HTML, etc. I want to move my WordPress installation so that visitors to hashbang0.com see the WordPress site. At the same time, anyone with links to the old blog.hashbang0.com (most notably RSS feeds and a few links spattered about which gain a fair amount of traffic, etc.) shouldn't be cut off (possibly be redirected to the appropriate thing on hashbang0.com).
I guess I could possibly change the site config to:
<VirtualHost 123.456.789.000:80>
ServerAdmin user#gmail.com
ServerName hashbang0.com
ServerAlias www.hashbang0.com
DocumentRoot /home/user/public_blog/
ErrorLog /home/user/log/error.log
CustomLog /home/user/log/access.log combined
</VirtualHost>
And I guess I'd need to update the URL in Settings > General?
I don't want to start moving stuff and find I've shot myself in the foot. The WordPress howtos are great, but riddled with if this and if that...
Any help would be very much appreciated.
Ben
Ben,
Your best bet is to litterally move the entire blog folder over to your public folder. In this case, you will want to write a redirect htaccess script on the blog subdomain.
RewriteCond %{HTTP_HOST} ^blog\.mydomain\.com$ [NC]
RewriteRule ^(.*) http://www.mydomain.com/$1 [L,R]
In a Command Line Interface, CLI,
You would
cp -r ~/public_blog ~/public_html
make sure to make back ups! And when you are all done, create the .htaccess file in ~/public_blog and delete the old files.
You may want to look into adding a 301 Redirect so google knows you moved also.
Before you do anything, create a copy of this file. Then if you mistype anything, you just overwrite the original with the copy.
Currently your website is located in directory public_blog. To have users access this WP from hash bang, you either need to rewrite the DocumentRoot for hashbang from public_html to public_blog or you need to move the entire site directory structure to the root directory in public_html.