In the www root folder of my web server I have 2 folders for 2 differents websites
www/firstsite
www/secondsite
To reach the index.php file of the first site I go to www.firstsite.com/firstProject
To reach the index.php file of the second website I go to www.secondsite.com/secondProject
I would like to put an unique htaccess file in the root folder "www". This htaccess file would have a rewriterule for both webstie.
So users would see www.firstsite.com instead of www.firstsite.com/firstProject
and www.secondsite.com instead of www.secondsite.com/secondProject
Edit: I use this htaccess to rewrite the url of www.firstsite.com(don't forget this website is located in folder www/firstsite:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ firstsite/$1 [QSA,L]
</IfModule>
Edite: here is the answer thank you to hjpotter92 !
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?firstsite\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/firstProject [NC]
RewriteRule ^(.*)$ /firstProject/$1 [L]
RewriteCond %{HTTP_HOST} ^(?:www\.)?secondsite\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/secondProject [NC]
RewriteRule ^(.*)$ /secondProject/$1 [L]
Use the %{HTTP_HOST} variable to test your domain name, and redirect based on that:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?firstsite\.com$ [NC]
RewriteCond %{REQUEST_URI} !^/firstProject [NC]
RewriteRule ^(.*)$ /firstProject/$1 [L]
similar rules will go for your second domain.
Related
Situation: afwezigheden.eu is the main domain with a few coupled domains (= aliases?) like skatespots.be, inviteme.eu, halftwaalf.be... Now I'm trying to redirect those aliasses to a subfolder, without the users seeing it.
Al those sites are in a subfolder _DOMAINNAME. For example: skatespots.be is in afwezigheden.eu/_skatespots
Also I have an SSL certificate, so I would like to redirect all domains to https too.
I tried several things, the last one is this one, where skatespots seems to work and everything is redirected over https.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/_skatespots/
RewriteCond %{HTTP_HOST} ^(www\.)?skatespots\.
RewriteRule ^(.*)$ /_skatespots/$1 [L]
RewriteCond %{REQUEST_URI} !^/_halftwaalf/
RewriteCond %{HTTP_HOST} ^(www\.)?halftwaalf\.
RewriteRule ^(.*)$ /_halftwaalf/$1 [L]
RewriteCond %{REQUEST_URI} !^/_inviteme/
RewriteCond %{HTTP_HOST} ^(www\.)?inviteme\.
RewriteRule ^(.*)$ /_inviteme/$1 [L]
RewriteCond %{HTTP:X-Forwarded-Proto} !http
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
What am i doing wrong?
What if you put the folder structure as this:
afwezigheden.eu/sites/skatespots.eu
afwezigheden.eu/sites/halftwaalf.eu
And then use this in your afwezigheden.eu/.htaccess
RewriteEngine on
RewriteCond %{REQUEST_URI} !sites/
RewriteRule (.*) /sites/%{HTTP_HOST}/$1 [L]
I have two domains, autodromodifranciacorta.it and franciacortacircuit.com both pointing to the same website hosted on this IP address: 94.23.64.40.
Now i want all the content to be under one single domain, so i decided to 301 redirect all the traffic from franciacortacircuit.com to autodromodifranciacorta.it
Here is my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The redirect is not working and i have no clue why, because the syntax looks correct to me.
The .htaccess file is processed, because if i put a typo in it, i get server error.
Wha'ts wrong with it?
Your second http_host condition is wrong and it never matches if the current host is franciacortacircuit.com, You need to use an OR condition to match against 2 diffrent hosts.
#Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
When I go to
www.mydomain.tld/sk/
everything works fine, link is not changed.
But when I delete forward slash
www.mydomain.tld/sk
the page is changed to
www.mydomain.tld/domains/mydomain.tld/sk/?lang=sk
Can anybody help please? How can avoid the link to be changed?
When I go to www.mydomain.tld/sk I need it to remain the same.
.htaccess file (1):
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
RewriteRule ^sk$ /index.php?lang=sk [L,QSA]
RewriteRule ^sk/$ /index.php?lang=sk [L,QSA]
RewriteRule ^sk/index /index.php?lang=sk [L,QSA]
There is another one .htaccess file (2) in the top main directory
and it contains these lines
RewriteEngine On
RewriteCond %{REQUEST_URI} !^domains/
RewriteCond %{REQUEST_URI} !^/domains/
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$
RewriteCond %{DOCUMENT_ROOT}/domains/%2 -d
RewriteRule (.*) domains/%2/$1 [DPI,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^domains/[^/]+/(.+[^/])$ /$1/ [R]
Options -indexes
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule /?([A-Za-z0-9_-]+)/?$ index.php?id=$1 [QSA,L]
This .htaccess file helps to navigate domains that I am running at server.
All web sites are in a directory /domains .
So for example www.mydomain.tld is pointing to /domains/mydomain.tld directory.
In this directory is the shorter htaccess file (1).
Not so easy, but I think it's because in .htaccess file (1) your link are from the root, and are not at root...
Try with: .htaccess file (1):
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
RewriteRule ^sk/?$ index.php?lang=sk [L,QSA]
RewriteRule ^sk/index index.php?lang=sk [L,QSA]
look at
RewriteCond %{REQUEST_URI} !^domains/
RewriteCond %{REQUEST_URI} !^/domains/
here are you testing if REQUEST_URI does not start with "domains" OR "/domains"
however in the previous htaccess, you guarantee that REQUEST_URI will start with www
you probably want REQUEST_FILENAME instead of REQUEST_URI here
I spent many hours by trying to solve it in htaccess, but nothing work.
So i just 301 redirect the wrong link in php:
if ($_SERVER['REQUEST_URI']=="/domains/mydomain.tld/sk/?lang=sk") {
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.mydomain.tld/sk/");
exit();
}
I am using Cakephp 2.0 and my website domain name is www.sample.com , If I try to access sample.com (with out www) then its going to www.sample.com this is fine. But My problem is my domain consists of lot of pages
for example :
> http://www.sample.com/users/login
> http://www.sample.com/users/add
If I access the above url like http://sample.com/users/login then it redirect to
> http://www.sample.com/index.php?url=users/login
but it needs to redirect to
http://www.sample.com/users/login
I already written the following code .htaccess file(before the app folder) to redirect
Rewritecond %{http_host} ^sample.com [NC]
Rewriterule ^(.*)$ http://www.sample.com/$1 [R=301,NC]
Inside webroot folder I have one .htacces file that contain the following code
may be that is the problem I think
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
Are you trying to always remove www or always keep www? This will add it:
## Add www
RewriteCond %{HTTP_HOST} !^www\.
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
## CakePHP
RewriteRule ^$ app/webroot/ [L]
RewriteRule (.*) app/webroot/$1 [L]
Try to write the next rule:
RewriteCond %{HTTP_HOST} ^sample.com [NC]
RewriteRule ^(.*)$ http://www.sample.com/$1 [L,R=301]
on app/webroot/.htaccess file, not on app's folder .htaccess. It works perfectly for me.
I have a website hosted in cpanel. Files of this website are in a folder. In the panel there is no possibility to host a domain to this folder, so when I go to www.mydomain.com I can see all folders. I would like to redirect my registered domain to a folder where my website is.
I use htaccess file and try this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^(.*)$ www.hostdomain.com/folder/$1 [L]
but it doesn't work.
This:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteRule ^(.*)$ folder/$1 [L]
and still nothing.
What I do wrong? I would be grateful for some advice.
Edit: I dealt with it.
I use:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mydomain.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/folder/
RewriteRule ^(.*)$ /folder/$1 [L]
then in order to hide joomla folder I add to joomla htaccess:
RewriteCond %{REQUEST_URI} !(\.|/$)
RewriteRule (.*) http://www.mydomain.com/$1/ [R=301,L]
RewriteCond %{REQUEST_URI} !^/folder
RewriteRule ^(.*)$ folder/$1 [L]
and next I change configuration.php file in joomla folder:
var $live_site = 'http://www.mydomain.com/';
It works.
Thanks a lot for your answers.
test it:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.mydomain.com$
RewriteCond %{REQUEST_URI} !^/path/to/folder/
RewriteRule ^(.*)$ path/to/folder/$1 [L]