merging sites and redirecting old urls - .htaccess

We have merged 2 sites and have to organise redirects from the domain that is now not in use.
The domain aquarestaurantblackheath.co.uk redirects fine, but not the old urls from that domain.
Any suggestions. see my code...
Working
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^/?$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/3\/1\/restaurant\-blackheath" [R=301,L]
Not working
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^section\/8\/1\/location$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/10\/1\/restaurant" [R=301,L]
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^section\/6\/1\/wines$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/8\/1\/food\-wine\-blackheath" [R=301,L]
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^section\/7\/1\/reservations$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/3\/1\/restaurant\-blackheath" [R=301,L]
The entire htaccess:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^aquabarandgrill.co.uk [NC]
RewriteRule ^(.*)$ http://www.aquabarandgrill.co.uk/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.aquabarandgrill.co.uk/ [R=301,L]
RewriteRule ^index\.html$ http://www.aquabarandgrill.co.uk/ [R=301,L]
RewriteRule ^index\.htm$ http://www.aquabarandgrill.co.uk/ [R=301,L]
RewriteEngine on
Options +SymlinksIfOwnerMatch +MultiViews
RewriteRule ^(.*).php/(.*) $1.php?$2
## Bromley old site REDIRECTS (PERMANANT 301) ##
RewriteRule ^Home.php?id=Menus/?$ http://www.aquabarandgrill.co.uk/section/2/1/restaurant-bromley/ [L,R=301,NC]
#
## Deafult character encoding UTF-8 / ISO-8859-1
AddDefaultCharset ISO-8859-1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^aquarestaurantblackheath\.co\.uk$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquarestaurantblackheath\.co\.uk$
RewriteRule ^/?$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/3\/1\/restaurant\-blackheath" [R=301,L]
RewriteCond %{HTTP_HOST} ^aquabrasseriecroydon\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.aquabrasseriecroydon\.com$
RewriteRule ^/?$ "http\:\/\/www\.aquabarandgrill\.co\.uk\/section\/4\/1\/restaurant\-croydon" [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^(/?|section/7/1/reservations)$ http://www.aquabarandgrill.co.uk/section/3/1/restaurant-blackheath [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section\/8\/1\/location$ http://www.aquabarandgrill.co.uk/section/10/1/restaurant [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section\/6\/1\/wines$ http://www.aquabarandgrill.co.uk/section/8/1/food-wine-blackheath [R=301,L]

Try the following rules:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^(/?|section/7/1/reservations)$ http://www.aquabarandgrill.co.uk/section/3/1/restaurant-blackheath [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section/8/1/location$ http://www.aquabarandgrill.co.uk/section/10/1/restaurant [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section/6/1/wines$ http://www.aquabarandgrill.co.uk/section/8/1/food-wine-blackheath [R=301,L]
EDIT
After seeing the whole htaccess file, remove everything in there, and replace the whole file with the following piece of code:
AddDefaultCharset ISO-8859-1
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^(/?|section/7/1/reservations)$ http://www.aquabarandgrill.co.uk/section/3/1/restaurant-blackheath [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section/8/1/location$ http://www.aquabarandgrill.co.uk/section/10/1/restaurant [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?aquarestaurantblackheath\.co\.uk [NC]
RewriteRule ^section/6/1/wines$ http://www.aquabarandgrill.co.uk/section/8/1/food-wine-blackheath [R=301,L]
RewriteRule ^(.*)\.php/(.*) $1.php?$2 [L]

Related

.htaccess - conditionaly redirect subfolders

I would like to implement followin in .htaccess file:
I have "dictionary", which tells me, which subfolder should be redirected where, i.e.
domain1.com/a -> domain2.com/x
domain1.com/b -> domain2.com/y
and everything else should be redirected to
domain2.com/z
That should be simple enough, but I can not figure it out.
My code:
RewriteEngine on
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ - [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ - [env=proto:http]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com/a$ [NC]
RewriteRule ^(.*)$ %{ENV:proto}://domain2.com/x [L]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com/b$ [NC]
RewriteRule ^(.*)$ %{ENV:proto}://domain2.com/y [L]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$ [NC]
RewriteRule ^(.*)$ %{ENV:proto}://domain2.com/z [L]
Variable %{HTTP_HOST} only matches domain not request uri.
You can use these rules:
RewriteEngine on
RewriteCond %{HTTPS} =on
RewriteRule ^(.*)$ - [env=proto:https]
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ - [env=proto:http]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
RewriteRule ^a/?$ %{ENV:proto}://domain2.com/x [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
RewriteRule ^b/?$ %{ENV:proto}://domain2.com/y [L,NC,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain1\.com$ [NC]
RewriteRule ^ %{ENV:proto}://domain2.com/z [L,NC,R=301]

how to redirect www.xyz.com/webmail to mail.xyz.com through .htaccess

RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^webmail$ "http\:\/\/mail\.domain\.com\/" [R=301,L]
But Above code in .htaccess is not working however given below code is working
RewriteCond %{HTTP_HOST} ^domain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.domain\.com$
RewriteRule ^folderName\/$ "http\:\/\/www\.domain\.net\/" [R=301,L]
Try using this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^www.xyz.com
RewriteRule ^webmail/(.*)$ http://mail.xyz.com/$1 [L,R=301]
EDIT:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?xyz\.com$
RewriteRule ^webmail/(.*) http://mail.xyz.com/$1 [R=301,L]

I want to rewrite subdomains and folders to params

I like to rewrite my subdomain site (wildcard) and when exists folders to params for the index.php file.
So
www.domain.com
www.domain.com/js/file.js
www.domain.com/css/file.css
www.domain.com/images/file.jpg
should be preserved!
And these should change to parameters for index.php
sub.domain.com/
to
www.domain.com/index.php?key1=sub
sub.domain.com/2015
to
www.domain.com/index.php?key1=sub&key2=2015
sub.domain.com/2015/12
to
www.domain.com/index.php?key1=sub&key2=2015&key3=12
Is this possible?
What I have sofar is
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
RewriteRule ^/?(.*)$ $1?page=%1 [QSA,L,NE]
Thank you very much!
So I rewritten some of #anubhava his htaccess to this
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.gebruikmaar\.nl [NC]
RewriteRule ^/?(.*)$ $1?page=%1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.gebruikmaar\.nl [NC]
RewriteRule ^(.*)([^/][0-9]*)(/?)$ $1?page=%1&key2=$1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.gebruikmaar\.nl [NC]
RewriteRule ^(.*)([^/][0-9]*)/([^/][0-9]*)(/?)$ $1?page=%1&key2=$1&key3=$2 [QSA,L]
And it almost works!
This url:
http://agenda.gebruikmaar.nl
Becomes
http://www.gebruikmaar.nl/index.php?page=agenda
BUT :-(
This url:
http://agenda.gebruikmaar.nl/2015
Becomes:
http://www.gebruikmaar.nl/index.php?page=agenda&key1=201
So where's the last character (5) at?
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
# skip all files and directories from rewrite rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
RewriteRule ^/?$ index.php?key1=%1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
RewriteRule ^([^/]+)/?$ index.php?key1=%1&key2=$1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ index.php?key1=%1&key2=$1&key3=$2 [QSA,L]

how to use .htaccess to redirect all http traffic to https AND www.domain.com

I've tried several solutions posted here, none of them seem to work - I just get redirect errors.
What I am trying to do is redirect all traffic to https for:
http://domain.com
http://www.domain.com
https://domain.com
http://alias.com
http://www.alias.com
https://alias.com
should all go to: https: // www.domain.com
currently addresses starting like: http: // www won't redirect to https.
here is the htaccess file
RewriteEngine On
RewriteBase /
# Fix Apache internal dummy connections from breaking [(site_url)] cache
RewriteCond %{HTTP_USER_AGENT} ^.*internal\ dummy\ connection.*$ [NC]
RewriteRule .* - [F,L]
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
# Exclude /assets and /manager directories from rewrite rules
RewriteRule ^(manager|assets) - [L]
# For Friendly URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^myalias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myalias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^myotheralias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myotheralias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
You should get rid of the www redirects at the bottom:
RewriteCond %{HTTP_HOST} ^myalias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myalias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
RewriteCond %{HTTP_HOST} ^myotheralias.ca$ [OR]
RewriteCond %{HTTP_HOST} ^www.myotheralias.ca$
RewriteRule ^/?$ "https\:\/\/mydomain\.com" [R=301,L]
Don't need them, you just need a single redirect at the top, replace:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^mydomain\.com [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [R=301,L]
with
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\.mydomain\.com$ [NC]
RewriteRule ^(.*)$ https://www.mydomain.com/$1 [L,R=301]
This should take care of all the redirects.

dynamic subdomains using .htaccess in php

i am trying to implement dynamic
RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^/?$ /live/agent/index.php?agent_user_name=%1 [L]
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^(.+?)/?$ /live/agent/$1.php?agent_user_name=%1 [L]
Now this .htaccess converts
http://mydomain.com/live/agent/index.php?agent_user_name=username to http://username.mydomain.com
and
http://mydomain.com/live/agent/forum.php?agent_user_name=username to http://username.mydomain.com/form/
However, there are other pages as well which i want to redirect to subdomain like
http://mydomain.com/live/agent/view_blog.php?agent_user_name=username&blog_id=19 this page should be read via subdomain something like http://username.mydomain.com/view_blog/19 etc and also
http://mydomain.com/live/agent/page.php?agent_user_name=username&content_id=19 this page should be accessed by http://username.mydomain.com/content/19 etc
Thanks
This should work:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^content/([0-9]+)/?$ /live/agent/page.php?agent_user_name=%1&blog_id=$1 [L,QSA]
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^([^/]+)/([0-9]+)/?$ /live/agent/$1.php?agent_user_name=%1&blog_id=$2 [L,QSA]
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^/?$ /live/agent/index.php?agent_user_name=%1 [L]
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.mydomain\.com$ [NC]
RewriteRule ^(.+?)/?$ /live/agent/$1.php?agent_user_name=%1 [L]
Add the following below your current rules should achieve what you want.
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /live/agent/view_blog.php\?agent_user_name=(.*)&blog_id=(.*)\ HTTP
RewriteRule ^ http://%2.mydomain.com/view_blog/%3? [R,L]
RewriteCond %{THE_REQUEST} ^(GET|POST)\ /live/agent/page.php\?agent_user_name=(.*)&content_id=(.*)\ HTTP
RewriteRule ^ http://%2.mydomain.com/content/%3? [R,L]

Resources