I have a little problem. I have a hosting with piensasolutions and two domains. The first domain controls the hosting and the second use a domain parking.
Let a.com be the first domain and b.com be the second domain.
My domain parking for b.com allows me to redirect from b.com to a.com/folder, (where folder contains the web page where I want to point with b.com).
The problem is that I want to show b.com URL instead of a.com/folder URL, I am not sure if the problem is from piensasolutions because I tried several .htaccess files but I was not able to change the URL of the web browser. This was my last test which supposes to keep the original URL.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?a.com/folder/$
RewriteRule ^(.*)$ /a.com/folder/$1 [L]
RewriteCond %{HTTP_HOST} ^(www.)?b.com$
RewriteRule ^(.*)$ /b.com/$1 [L]
For additional information, I put the .htaccess file inside the a.com/folder. I am not sure about the redirection of piensasolutions.
If your are able to help me, I will be really grateful, and also if you have dedicated a couple of minutes even if you have not find the anwser.
Thank you!
I think that the best way is usig sites-avaiable.
First of all,
$ vi /etc/host
and copy the next line:
127.0.0.1 a
127.0.0.1 b
Then, create two new sites:
$ touch /etc/apache2/sites-avaiable/a
$ touch /etc/apache2/sites-avaiable/b
and edit them
$ vi /etc/apache2/sites-avaiables/a
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName a
DocumentRoot /your_path_to_server/a/folder
<Directory /your_path_to_server/a/folder/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
and
$ vi /etc/apache2/sites-avaiables/b
<VirtualHost *:80>
ServerAdmin webmaster#localhost
ServerName b
DocumentRoot /your_path_to_server/b
<Directory /your_path_to_server/b/>
Options FollowSymLinks
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
and that's all. This should work.
Related
I have a website, say domain1.example, deployed on an Amazon EC2 machine with apache2.
I want to point domain2.example to domain1.example/path.
Basically like this:
domain2.example -> domain1.example/path
domain2.example/one -> domain1.example/path/one
domain2.example/two/page -> domain1.example/path/two/page
(Without changing the URL in the browser's address bar)
I have tried these methods:
Adding a rewrite rule to /etc/apache2/sites-available/000-default.conf
...
<VirtualHost *:80>
ServerName "domain2.example"
ServerAdmin email#domain1.example
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
RewriteEngine On
RewriteRule ^(.*)$ https://domain1.example/path/$1 [P]
<Directory /var/www/html>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Require all granted
</Directory>
</VirtualHost>
Adding a rewrite rule to .htaccess in the project folder
RewriteCond %{HTTP_HOST} ^domain2\.example [NC]
RewriteRule ^(.*)$ https://domain1.example/path/$1 [P]
Neither of them works. Both domains are serving the root folder. Am I doing something wrong?
I would implement this using separate virtual hosts for the two domains that have different document roots.
<VirtualHost *:80>
ServerName "domain1.example"
DocumentRoot /var/www/html
...
</VirtualHost>
<VirtualHost *:80>
ServerName "domain2.example"
DocumentRoot /var/www/html/path
...
</VirtualHost>
While this will accomplish your goal, I would not recommend setting up websites like this.
If both sites have .htaccess files they can conflict with each other. You may see different behavior when accessing the content on the different domains because of which rules apply to in the two scenarios.
Search engines prefer to find content on just one "canonical" URL. When you serve the same content on multiple domains it can confuse search engines and hurt your SEO.
Dear people,
My goal is to set up the apache2's 000-default.conf and the .htaccess in a specific way, so the user will always be redirected to a specific php file (index.php for example) if they (the user) wants to access the web app, which I am building.
Examples :
example-app.local
example-app.local/hello-world
example-app.local/admin.php
example-app-local/../../../../my-passwords.txt
All of them should point to index.php. I followed several tutorials, but I guess I need a specific tutorial for me, so that I can fully understand the concepts of apache2 and its configurations. Feel free to judge me - I am alright with criticism.
What I have in my files is the following
1. The 000-default.conf file which is located in /etc/apache2/sites-available/
<VirtualHost *:80>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
ServerAdmin webmaster#localhost
DocumentRoot /var/www
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
...and loads of comments
2. The example-app.local.conf file which is located in /etc/apache2/sites-available/
<VirtualHost *:80>
ServerAdmin admin#example.com
ServerName example-app.local
ServerAlias www.example-app.local
DocumentRoot "/var/www/example-app"
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
3. The .htaccess file which is located in /var/www/example-app/
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,R]
What I get is the following : "Apache default conf is like a god of the configurations and you can state specifically that you can AllowRedirect which will magically trigger the functionality of htaccess and there you need the even more magical syntax to make every request from the user point ONLY to the index.php" Is this correct?
What is working Apache is working. I am enabling and disabling configs via
sudo a2ensite 000-default.conf
sudo a2dissite 000-default.conf
and then I restart and check that everything is fine via
sudo service apache2 restart
sudo service apache2 status
the status states active (running).
The content of /etc/hosts is also edited in a correct way, because I can actually see the content of the index.html file when I try to point my browser to the example-app.local page. I would also like to point out that I have php installed correctly - I tested it via the phpinfo function/method.
I tried several tutorials and none of them helped me. I believe I am missing something important and I am too 'blind' to see it, so I need someone to 'open' my eyes, so please - help me.
Best regards,
Yet another confused startup developer,
Bobkoo
Try tis one:
After RewriteEngine On try RewriteBase / and lose the slash before index.php
BTW you working on Windows... so the DocumentRoot "/var/www/example-app" should be something like C:\xampp\htdocs\project-folder
I know this is quite old problem, but i have no luck when trying to find the right solution. I have tried every possible configuration but still no luck. I'm working on PHP project using laravel. I got no problem at all when set up the laravel.labs as vhost INSIDE the htdocs. But when I move it into separated folder which is C:\vhosts i got this 403 error. The purpose of vhosts folder is to hold multiple vhost. The following are my configuration:
System:
windows 7 64-bit
XAMPP v 1.7.7
Apache/2.2.21
PHP: 5.3.8
httpd.conf :
# Virtual hosts
Include "conf/extra/httpd-vhosts.conf"
httpd-vhosts.conf
NameVirtualHost *:80
<VirtualHost *:80>
DocumentRoot C:/xampp/htdocs
ServerName localhost
</VirtualHost>
<VirtualHost *:80>
DocumentRoot c:/vhosts/laravel_labs/public
ServerName laravel.labs
</VirtualHost>
c:\windows\system32\driver\etc\host
# localhost name resolution is handled within DNS itself.
# 127.0.0.1 localhost
# ::1 localhost
127.0.0.1 laravel.labs
.htaccess (inside the C:\vhosts\laravel_labs\public)
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
Can anyone help to find something that i missed? any advice guys? thanks
Every time you add a new Alias or DocumentRoot, you need a <directory> section just like the one for your default DocumentRoot. Depending on your release, this either has something like
Order deny,allow
or
require all granted
Finally i found The answer for this problem. I have to add some lines in httpd.conf
Something like this:
Alias /laravel_labs/public "C:/vhosts/laravel_labs/public/"
<Directory "C:/vhosts/laravel_labs/public/">
AllowOverride All
Order Allow,deny
Allow from all
</Directory>
See the detail explanation here :
http://www.youtube.com/watch?v=Z250saioXIs
In my /var/www I have a number of sites (goodsite, badsite, uglysite). Right now they are accessed by mydomain.com/goodsite, etc..
What I want is for one site in particuar, uglysite, to be accessed by uglysite.mydomain.com - the others remain as they are.
I have tried all sorts of ways of fiddling with the.htaccess (in /var/www). Note I have mod-rewrite enabled and mod vhost-alias enabled.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^uglysite\.mydomain\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/uglysite/
RewriteRule ^(.*)$ /uglysite/$1 [L]
What ends up happening is that both mydomain.com and uglysite.mydomain.com always map to the same thing (i.e., the index at /var/www). I tried adding in a new virtual host, and was surprised to find that uglysite.mydomain.com mapped correctly, but then mydomain.com also mapped directly to uglysite as well.
<Virtualhost uglysite.mydomain.com:80>
ServerName uglysite.mydomain.com
ServerAdmin www#localhost
DocumentRoot "/var/www/"
AccessFileName .htaccess
<Directory "/var/www/uglysite">
Order allow,deny
Allow from All
AllowOverride All
</Directory>
</VirtualHost>
The above was added to my sites-enabled/000-default file. This got uglysite.mydomain.com to work properly, but then mydomain.com mapped to the same thing!
Is there a straightforward way to do what I'm intending to do?? Thanks in advance.
You should be making uglysite into a second file instead of modifying 000-default
So, take a copy of the 000-default file, change the subdomain as you have done up there and modify the directory to /path/to/site
000-default:
<Virtualhost *:80>
ServerName mydomain.com
ServerAdmin www#localhost
ServerAlias mydomain.com
DocumentRoot "/var/www/goodsite"
AccessFileName .htaccess
<Directory "/var/www/goodiste">
Order allow,deny
Allow from All
AllowOverride All
</Directory>
</VirtualHost>
uglysite:
<Virtualhost *:80>
ServerName uglysite.mydomain.com
ServerAlias uglysite.mydomain.com
ServerAdmin www#localhost
DocumentRoot "/var/www/uglysite"
AccessFileName .htaccess
<Directory "/var/www/uglysite">
Order allow,deny
Allow from All
AllowOverride All
</Directory>
</VirtualHost>
Also note that in the above samples, I have modified the DocumentRoot to point to the directory that you want file served from
EDIT: virtualhosts set to *:80 since your sites point to your own ip anyway
My apache server is set up with a very basic configuration. I used to serve just one website from apache, let's call it example.com. Within the httpd.conf file, I had some code to force the website to always show www in the url.
I recently added a subdomain for the site, blog.example.com. In order to do this I needed to create 2 virtual directory directives within my httpd.conf file.
NameVirtualHost *:80
<VirtualHost *:80>
ServerName example.com
DocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName blog.example.com
DocumentRoot /var/www/blog
</VirtualHost>
Immediately after this, I kept my rewrite code:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.example\.com [NC]
RewriteCond %{HTTP_HOST} !^$
RewriteRule ^/(.*) http://www.example.com/$1 [L,R]
The problem is that this after adding the Virtual Directory code, the rewrite code is no longer working. I tried creating the following Directory directive, which doesn't seem to work at all.
<Directory "/var/www/html">
Options Indexes MultiViews FollowSymLinks
Order Deny,Allow
Allow from all
AllowOverride All
</Directory>
Additionally, I tried creating a .htaccess file in the html folder of the website and restarting apache, but nothing that I put in there is getting noticed at all.
Any help is greatly appreciated. Thanks!
Answer from comment by original poster:
Ok, I figured it out. I just needed to move the rewrite logic within the start and end Directives. Thanks for the help #animuson. – Henry Wrinkler