Adding blog to an existing website with the same domain name - apache

I have a working website in Yii frame work with domainename.fr
Now i want to add a wordpress blog to be accessible in : domainename.fr/wp
I have tried to add a rewrite rule in the .htaccess file but it overrided by another rule that redirect every unknown path to the root (domainename.fr).
How can i do that with just alias, i mean to point /wp to /path_of_my_blog
my .conf file
<VirtualHost *:80>
ServerName domainename.fr
DocumentRoot /var/www/path/htdocs/src/web
<Directory /var/www/path/htdocs/src/web>
Options +Indexes
AllowOverride All
</Directory>
ErrorLog /var/log/apache2/project_error.log
CustomLog /var/log/apache2/project_access.log combined
</VirtualHost>
my blog path is /var/www/path/htdocs/wp

Related

Keep original URL after redirection by domain provider

Goal
fharrell.com/* is redirected by the domain provider to hbiostat.org/blog/*. I want to keep the address bar showing fharrell.com/*
Apache2 Setup
/etc/apache2/apache2.conf is standard with the following exception:
<Directory /home/ubuntu/htdocs/>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
/etc/apache2/sites-enabled/hbiostat.org.conf is symbolically linked from /etc/apache2/sites-available/hbiostat.org.conf
hbiostat.org.conf sets the document root as /home/ubuntu/htdocs which has been working well for some time
Contents of hbiostat.org.conf:
<VirtualHost *:443>
ServerAdmin my#email.address
DocumentRoot /home/ubuntu/htdocs
ServerName hbiostat.org
ServerAlias www.hbiostat.org
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
<Directory /home/ubuntu/htdocs>
Options FollowSymLinks
AllowOverride None
Require all granted
</Directory>
<Directory /home/ubuntu/htdocs/blog>
RewriteEngine on
RewriteBase /
RewriteRule ^hbiostat\.org/blog$ fharrell.com [R]
</Directory>
Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/hbiostat.org/fullchain.pem
SSLCertificateKeyFile /etc/letsencrypt/live/hbiostat.org/privkey.pem
</VirtualHost>
<VirtualHost *:80>
ServerName hbiostat.org
ServerAlias www.hbiostat.org
DocumentRoot /home/ubuntu/htdocs
<Directory /home/ubuntu/htdocs/blog>
RewriteEngine on
RewriteBase /
RewriteRule ^hbiostat\.org/blog$ fharrell.com [R]
</Directory>
</VirtualHost>
Systax was checked using sudo apachectl -t.
I checked that mod rewrite is active using sudo a2enmod rewrite and restarted the server with sudo systemctl restart apache2
But this has no effect, with hbiostat.org/blog/* remaining in the addressbar.
Tried:
Many remedies on stackoverflow.com (including the two below) and elsewhere, including putting the commands into an .htaccess file (I'd like to avoid the .htaccess approach).
Any help appreciated.
Redirect domain but keep original url
Redirect subfolder URL but keep original domain name
You can't make the browser display a different domain after a 30x redirect.
mod_rewrite doesn't do what you're thinking it does.

Make all subdomains point to on single file/folder using ".conf" file

I wanted to redirect all my subdomain to a single file/folder I done the pointing thing before using .conf files in apache but I did it for a specific domain.
this is the conf file that I use for pointing the domain.
listen 80
<VirtualHost *:80>
ServerName subdomain.domain.com
DocumentRoot /var/www/html/project/dist
<Directory /var/www/html/project/dist>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
but what I want is to redirect all the subdomain to redirect to the same project which has some domain for example:-
currently, the upper conf file will redirect to my project folder but what I want is that if I have domain-like
sd1.domain.com
sd2.domain.com
sd3.domain.com
they should also point to the same project directory. but I am not sure how to do it
thx in advance
I solved my problem by doing a slight change into my .conf file here is my new file
listen 80
<VirtualHost *:80>
ServerName domain.com
ServerAlias *.domain.com
DocumentRoot /var/www/html/project/dist
<Directory /var/www/html/project/dist>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
what I did I add the server alias to (*) which let me allow to redirect all my subdomain to single project.

Creating a subdomain through vhost or htaccess

Currently working on a project on my local xampp setup. I am using a test domain like so: testsite.devs. Now, I want to create an admin interface using the subdomain admin.testsite.devs. I have it working, but Im currently using vhost like so:
<VirtualHost testsite.devs:443>
DocumentRoot "D:/websites/testsite"
ServerName testsite.devs
ServerAlias testsite.devs
ErrorLog "logs/testsite.devs-error.log"
CustomLog "logs/testsite.devs-access.log" combined
<Directory "D:/websites/testsite">
Require all granted
</Directory>
SetEnv ENVTYPE "dev"
SSLEngine on
SSLCertificateFile "crt/testsite.devs/server.crt"
SSLCertificateKeyFile "crt/testsite.devs/server.key"
</VirtualHost>
<VirtualHost admin.testsite.devs:443>
DocumentRoot "D:/websites/testsite/admin"
ServerName admin.testsite.devs
ServerAlias admin.testsite.devs
ErrorLog "logs/admin.testsite.devs-error.log"
CustomLog "logs/admin.testsite.devs-access.log" combined
<Directory "D:/websites/testsite/admin">
Require all granted
</Directory>
SetEnv ENVTYPE "dev"
SSLEngine on
SSLCertificateFile "crt/testsite.devs/server.crt"
SSLCertificateKeyFile "crt/testsite.devs/server.key"
</VirtualHost>
It appears to work, but Im thinking if I dont have access to a vhost file, is there a easier way to just do this via the htaccess file? I tried examples found online like so:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^admin.testsite.devs
RewriteRule ^(.*)$ testsite.devs/admin/$1 [L,NC,QSA]
But if I go to:
admin.testsite.devs/index.html
The URL changes to:
testsite.devs/admin/index.html
So using htaccess, how do I create the sub domain where the URL stays the same? So if I go to admin.testsite.devs/index.html, it stays that way in the URL bar?

Redirect to a subfolder in Apache virtual host file

I have Joomla installed on a webserver running Ubuntu Server 12.04. The Joomla folder is located at /var/www/cms/.
My vhost file at /etc/apache2/sites-enabled/default has the following content:
<VirtualHost *:80>
ServerName domain.com/
Redirect permanent / https://domain.com/
</VirtualHost>
<VirtualHost *:443>
ServerAdmin webmaster#localhost
ServerName domain.com:443
DocumentRoot /var/www/cms
<Directory />
Options FollowSymLinks
AllowOverride All
</Directory>
<Directory /var/www/cms>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
(...)
</VirtualHost>
At the moment, all the requests to domain.com and anything entered after that like domain.com/example gets directed and processed by Joomla which either redirects to a proper page or returns a custom 404 error. This all works.
Now, I would like to filter all the requests that go to domain.com/subfolder before they get processed by Joomla and redirect them to /var/www/subfolder (instead of my root folder at /var/www/cms/).
I believe the file in /etc/apache2/sites-enabled/default (seen above) is the right place to define such a redirect, however I have not been able to figure out at what position and how to achieve this.
You should add to your configuration:
Alias /subfolder /var/www/subfolder
<Directory /var/www/subfolder>
Order allow,deny
allow from all
</Directory>
and fit the configuration between "Directory" to your needs.
See the Apache documentation to have more informations.

Multiple versions of a website each with its own root directory using Apache

I have multiple versions of my website. Each resides in its own folder, for example:
site_v1/
index.html
page1.html
site_v2/
index.html
page1.html
How can I configure apache so that each version of the site has its own definition of the root directory?
In other words, I want site_v1/index.html to think the root directory is site_v1, and site_v2/index.html to think the root directory is site_v2
You are looking for the VirtualHost directive.
Apache manual on virtual hosts
As #Pekka wrote, you are indeed looking for the VirtualHost directive, but I though I might add an example configuration for your virtual host configuration. This should be placed in your httpd.conf file, edited to your preference, and remember to fill in the full path:
NameVirtualHost v1.yoursite.com:80
<VirtualHost v1.yoursite.com:80>
ServerName v1.yoursite.com
ServerAlias v1.yoursite.com
DocumentRoot /path/to/site_v1
ErrorLog /path/to/prefered/error.log
CustomLog /path/to/prefered/access.log combined
<Directory /path/to/site_v1>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
NameVirtualHost v2.yoursite.com:80
<VirtualHost v2.yoursite.com:80>
ServerName v2.yoursite.com
ServerAlias v2.yoursite.com
DocumentRoot /path/to/site_v2
ErrorLog /path/to/prefered/error.log
CustomLog /path/to/prefered/access.log combined
<Directory /path/to/site_v2>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
If you want, you may chose to use a different access/error log for each version of your site. Just change the name/path to the log file, and you're done. /path/to are the path to the site folder, and v1.yoursite.com & v2.yoursite.com should be changed to the relative domains you want to use for each version. If you don't want to change the log files, remove the ErrorLog and CustomLog directives and I'll default to the main log files set in httpd.conf