Cannot 301 Redirect Addon Domain - .htaccess

.
I have the current setup:
primarysite.com/addondomain1.net
primarysite.com/addondomain2.net
primarysite.com/addondomain3.net
.
Here is what I want to accomplish:
I would like anyone (or spiders) who try to access primarysite.com/addondomain1.net to be served addondomain1.net instead.
For example, if someone were to attempt to access primarysite.com/addondomain1.net/about.php, they would instead be served addondomain1.net/about.php
.
The Problem:
I have tried to set the .htaccess file for each subdirectory of primarysite.com but it just doesn't work correctly. Here is my current settings placed within each addon domain:
RewriteCond %{HTTP_HOST} ^(www\.)?primarysite\.com$ [NC]
RewriteRule ^ "http://addondomain1.net/" [L,R=301]
.
I appreciate your help. I would gladly donate some BTC to the user who can solve this problem

Try:
RewriteCond %{HTTP_HOST} ^(www\.)?primarysite\.com$ [NC]
RewriteRule ^addondomain1\.net(.*)$ http://addondomain1.net$1 [L,R=301]
you'll need to do that for each of your add-ons.

You can place this rule in each sub-directory:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?primarysite\.com$ [NC]
RewriteRule (.*) http://addondomain1.net/$1 [L,R=301,NE]

Related

How to redirect dynamic subdomains with multiple query parameters

I would like to redirect
domain.com/test.php?username=username&code1=849&code2=4d1
to
username.domain.com/849/4d1
with .htaccess
At the moment I have
RewriteRule ^test/([^/]+)/([^/]+)/([^/]+) test.php?username=$1&code1=$2&code2=$3 [NC]
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule ^(.*) test.php?username=%1&code1=%2&code2=%3 [NC]
The redirect works but the code (php)
$code1 = $_GET['code1'];
echo $code1;
is empty. Can anyone point me in the right direction?
Thanks
Found it!
So if you want to redirect
username.domain.com/849/4d1
to
domain.com/test.php?username=username&code1=849&code2=4d1
You need to add below code to your .htaccess file:
RewriteCond %{HTTP_HOST} ^(^.*)\.domain.com
RewriteRule ^(.*)/([^/]+) test.php?username=%1&code1=$1&code2=$2 [NC]

.htaccess redirect a specific directory

I am in need of help with build an htaccess file. Basically I am moving an website from www.abc.com to www.xyz.com. Now, here is the two things that I am trying to achieve:
All users should be redirected to www.xyz.com when accessing www.abc.com
If user accesses www.abc.com/files/abcd.file or www.abc.com/files/folder/abcd.file, etc. should be redirected to arhive.xyz.com/abcd.file, etc. Basicly, this URL www.abc.com/files/, should be replaced with arhive.xyz.com, keeping the same file/directory structure.
Someone can help? Thanks in advance.
You have several requirements, but if I understand correctly this should get what you need in the htaccess file in the root directory.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteCond %{REQUEST_URI} !^/files(/.*)?$ [NC]
RewriteRule ^ http://www.newsite.com%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?oldsite\.com [NC]
RewriteCond %{REQUEST_URI} ^/files(/.*)?$ [NC]
RewriteRule ^ http://archive.newsite.com%{REQUEST_URI} [R=301,L]
Of course change to your domain names.

Htaccess redirect subdomains to a specific page without changing the link

I am working on a php script on which i will generate links with random subdomains.For example : x.domain.com sius.domain.com x5-.domain.com and so on. In fact these subdomains doesn't really exist what i want is that when user goes to any link (RANDOM).domain.com it shows the content of domain.com/result.php?rand=(RANDOM).
PS:I considered (RANDOM) as the variable. and i want to exclude www.
I tried this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteRule ^ http://domain.com/result.php [L,R]
But nothing seems to work. Can anyone help ?
Try with:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^(.+)\.domain\.com$ [NC]
RewriteRule ^ /result.php?rand=%1 [L,QSA]
You can't redirect (http://... and [R]) without link change. With this code you rewrite without redirection.

Redirect subdomain to different locations based on url

I have a website on a domain that I want to move to another domain. Here is my problem. The root URL has to redirect to a different location on the new domain. Example:
http://subdomain.olddomain.com/ must redirect to http://www.newdomain.com/location
http://subdomain.olddomain.com/code/slug must redirect to http://www.newdomain.com/slug
The htaccess code that I have doesn't work ver
RewriteRule ^/?(.*) http://www.newdomain.com/$1 [R=302,L]
This code works for the second example, but nog on the first. Can anyone help me setup the correct htaccess code?
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^code/(.*)$ http://www.newdomain.com/$1 [L,R]
RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^$ http://www.newdomain.com/location [L,R]

How do I redirect a subdomain to an HTML file?

I've been trying out all sorts of examples to redirect subdomains to files on my server.
So, let's say someone went to apple.domain.com.
Using htaccess, I want it to redirect to domain.com/apple.html
Here's the rules I have right now, which don't work.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?domain.com$ [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain.com$ [NC]
RewriteRule ^ /%1.html [L]
Thanks so much in advance for the help.

Resources