.htaccess rewrite subdirectory to a different subdirectory on a different domain - apache

I'm trying to configure a redirect for the domain kb3mmy.net. I'd like it to work that if somebody goes to kb3mmy.net/blog it redirects them to christiaanconover.com/category/kb3mmy/. This is the only redirect I want to take place like this, so I can hard code the subdirectories.
Also, there's an existing redirect rule set up on kb3mmy.net that sends any traffic to the root of that domain to a sub page on christiaanconover.com, but any sub page traffic to kb3mmy.net to the corresponding sub page on christiaanconover.com, so that rule cannot be affected by the new one. Here's the code for the existing rule:
RewriteRule ^$ http://christiaanconover.com/kb3mmy/ [L,R=301]
RewriteRule ^(.*)$ http://christiaanconover.com/$1 [R=301]
Any help is appreciated.

RewriteRule ^blog/?(.*)$ http://christiaanconover.com/category/kb3mmy/ [R=301,L]
RewriteRule ^$ http://christiaanconover.com/kb3mmy/ [L,R=301]
RewriteRule ^(.*)$ http://christiaanconover.com/$1 [R=301,L]

How about:
RewriteCond %{HTTP_HOST} kb3mmy.net
RewriteRule ^blog/?(.*)$ http://christiaanconover.com/category/kb3mmy/ [R=301,L]
RewriteCond %{HTTP_HOST} kb3mmy.net
RewriteRule ^$ http://christiaanconover.com/kb3mmy/ [L,R=301]
RewriteCond %{HTTP_HOST} kb3mmy.net
RewriteRule ^(.*)$ http://christiaanconover.com/$1 [L,R=301]

Related

Redirect from main page

I have a conditions:
a) Redirect from help.example.com to example.com/support
b) Redirect from other page, like help.example.com/catalog to example.com/catalog
This all I do in .htaccess file.
My code redirect me only on example.com/support
RewriteCond %{HTTP_HOST}${REQUEST_URI} ^help\.example\.com/(.+)
RewriteRule ^(.+)$ example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST}${REQUEST_URI} ^help\.example\.com
RewriteRule ^(.*)$ example.com/support/ [R=301,L]
How can I resolve this problem?
Please try this rules for yours a - b conditions:
a) Redirect from help.example.com to example.com/support
RewriteCond %{HTTP_HOST} ^help\.example\.com$ [NC]
RewriteRule ^(/?)$ https://example.com/support [R=301,L]
b) Redirect from other page, like help.example.com/catalog to example.com/catalog
RewriteCond %{HTTP_HOST} ^help\.example\.com$ [NC]
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
With your shown samples/attempts, please try following htacces rules in your htaccess file. Please place these rules at top of your file, also make sure to clear your browser cache before testing your URLs.
This will catch help.example.com OR www.help.example.com both kind of urls.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?help\.example\.com$ [NC]
RewriteRule ^/?$ https://example.com/support [NE,R=301,L]

Rewrite Condition with Special Case for Homepage

I switch my Business from one Domainname to another and want to use a 301 Redirect/Rewrite to keep the Google Ranking.
The special case is, that the Startpage and One other Page should go to a new Subpage on the new Domain, everything else should stay the same because of the structure of the new Domain is the same like the old one.
I tried several kinds of RegExp and another order. Maybe I misunderstand the path to a solution completly.
Maybe I should do a simple 301 Redirect on the Old Webpage and try to look into the referer on the New Apache Configuration and make an internal rewrite to /catvilla/
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.old.co.nz$ [NC]
RewriteRule ^(.*)$ https://www.new.co.nz/oldname/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www.old.co.nz/$ [NC]
RewriteRule ^(.*)$ https://www.new.co.nz/oldname/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www.old.co.nz/pricelist/$ [NC]
RewriteRule ^(.*)$ https://www.new.co.nz/oldpricelist/ [L,R=301]
RewriteCond %{HTTP_HOST} ^www.old.co.nz/ [NC]
RewriteRule ^(.*)$ https://www.new.co.nz/$1 [L,R=301]
The Apache Config in my VirtualHost right now, redirect everyging to www.new.co.nz/oldname all the time, eben for example for http://www.old.co.nz/webcam, what should go to www.new.co.nz/webcam.
Frank
So far I see the following is working:
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/$ [NC]
RewriteRule ^(.*)$ https://www.new.co.nz/oldname/ [L,R=301]
RewriteCond %{REQUEST_URI} ^/pricelist/$ [NC]
RewriteRule ^(.*)$ https://www.new.co.nz/oldpricelist/ [L,R=301]
RewriteRule ^(.*)$ https://www.new.co.nz/$1 [L,R=301]

htaccess sub domain pointing to a folder but dont want to redirect

I have setup a domain with DNS etc... and wanting to point it to use the /blog folder but when you go to blog.domain.com it just redirects to domains.com/blog - i would like to retain the blog.domain.com url if possible
code im have tried
RewriteCond %{HTTP_HOST} ^blog.domain.com
RewriteRule ^(.*)$ http://domain.com/blog/$1 [L,NC,QSA]
and also tried
RewriteCond %{HTTP_HOST} ^blog\.* [NC]
RewriteRule .* http://domain.com/blog/ [L]
Thanks in advance
This done the trick
RewriteCond %{HTTP_HOST} ^blog.domain.com$
RewriteCond %{REQUEST_URI} !blog/
RewriteRule (.*) /blog/$1 [L]

htaccess for rewriting only subdomain

I am trying to make a redirect for a subdomain but i can't figure it out.
This what I have now:
RewriteCond %{HTTP_HOST} ^(mysubdomain).myhost.com$ [NC]
RewriteRule (.*) http://www.myhost.com/folder/index.html [R=301,L]
But when I go to the subdomain address in my browser, there's no redirect.
I need this for only one specific subdomain.
Where am I going wrong?
Should be:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub.domain.com$ [NC]
RewriteRule ^.*$ http://www.domain.com/folder/ [R=301,L]
Try this, since you only need it from one domain. The () are pointless in both cases. Especially on the 2nd line where you aren't passing the old URL to the new URL.
RewriteCond %{HTTP_HOST} ^www.old-domain.com$ [NC]
RewriteRule ^.*$ http://www.myhost.com/folder/index.html [R=301,L]

RewriteCond and RewriteRule in .htaccess

I have a client folder located at http://www.example.com/client
However, I've now installed SSL on the server, and want to add a permanent redirect using HTACCESS so that whenever /client is accessed, that it redirects to: https://www.example.com/client
Anybody know how to do that?
I've redirected my domains in the past like this:
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
This should not affect the solution, but the site must still redirect to www.example.com FIRST, and then to https://www.example.com/client if for example, http://www.example.co.za/client is entered.
Try this:
RewriteCond %{HTTPS} !on
RewriteRule ^client(/.*)?$ https://www.example.com%{REQUEST_URI} [L,R=301]
RewriteEngine On
RewriteRule ^/?$ https://www.example.com/client [301,NC,L]
It tells the apache, whenever the url is https://www.example.com or either with slash at the end, will redirect to ur /client