Redirect from main page - apache

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]

Related

.htaccess rewriteCond part of the url

URL applying rule(s):
https://olddomain.ch/de/qahmkitd73/
https://olddomain.ch/fr/qahmkitd73/
https://olddomain.ch/en/qahmkitd73/
RewriteCond %{HTTP_HOST} chezcamillebloch\.ch$
RewriteCond %{REQUEST_URI} ^\/.*\/qahmkitd73\/$ [NC]
RewriteRule .* https://newdomain.ch/$1/qahmkitd73 [NE,R=301,L]
this should redirect to https://newdomain.ch/**/qahmkitd73
the ** should be dynamic from the URL (de/ or en/ or fr/)
You could keep your .htaccess rules file in following manner. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.ch$ [NC]
RewriteRule ^ http://newdomain.ch/%{REQUEST_URI} [R=301,NE,L]
this should redirect to https://newdomain.ch/**/qahmkitd73 the ** should be dynamic from the URL (de/ or en/ or fr/)
You may use this redirect rule:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(?:www\.)?olddomain\.ch$ [NC]
RewriteRule ^(en|fr|de)/qahmkitd73/?$ http://newdomain.ch%{REQUEST_URI} [R=301,NC,L]

Need to redirect 301 a URL in .htaccess file but it adds extra http//?

I am trying to redirect /abc.html to /abc.php but when I did it gives an extra http// and page is not working like http//www.example.de/abc.php don't know from where this HTTP comes.
note: website is not with ssl so domain name is http://example.de
My .htaccess file
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.de/$1 [R=301,L]
RedirectPermanent /tour.html /tour.php
With your shown samples/attempts, could you please try following. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^ http://%1%{REQUEST_URI} [NE,R=301,L]
##To serve home page link.
RewriteRule ^/?$ index.php [L]
RewriteCond %{REQUEST_URI} !^/?$
RewriteRule ^([^.]*)\.html/?$ $1.php [NC,L]

.htaccess dynamic subdomain files

here is my code in my .htaccess file:
RewriteCond %{HTTP_HOST} !^www\.domain\.com
RewriteCond %{HTTP_HOST} ([^.]+)\.domain\.com [NC]
RewriteRule ^/?$ /user/profile.php?name=%1 [L]
here is what it does:
if i visit test.domain.com, it will show the contents (not redirect) of domain.com/profile.php?name=test.
but if i type: test.domain.com/login, it will show the contents of the page: domain.com/login.
Question: why is that? how can i turn that off? thanks
Hope this will work, working fine on my end.
RewriteCond %{HTTP_HOST} !^www\.domain\.in
RewriteCond %{HTTP_HOST} ^test\.dmmain\.in [NC]
RewriteRule ^$ http://test.domain.in/user/profile.php [L,QSA]

.htaccess rewrite rule causes endless loop

I want my .htaccess file to redirect to some page if any wildcard as a subdomain entry hit the browser. i.e. I want
sam.xyz.com
To redirect to
sam.xyz.com/view.php?id=sam
I am using following rewrite rules for redirect.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.xyz.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).xyz.com
RewriteRule ^(.*)$ /view.php?id=%1 [L,R]
Problem i am facing is that it does not shift to new domain keeping query string instead it generates an endless loop
sam.xyz.com
redirects to
http://sam.xyz.com/view.php?id=sam
But doesnt move to url above without endless loop.
Kindly help me out.
Thanks in advance,
you should add a condition for redirect to prevent redirection loop:
RewriteCond %{REQUEST_URI} !^/view\.php
the whole code would be:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.xyz.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).xyz.com
RewriteCond %{REQUEST_URI} !^/view\.php
RewriteRule ^(.*)$ /view.php?id=%1 [L,R]
You are redirecting to: prefix.domain.tld/view.php?id=prefix
Ensure that the url does not contain: id=prefix.
This solution prevents, that someone call's the url: aaa.example.com/view.php?id=bbb
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.xyz.com [NC]
RewriteCond %{HTTP_HOST} ^([^.]+).xyz.com
RewriteCond %1::%{QUERY_STRING} !^([^:]+)::.*id=\1
RewriteRule ^ /view.php?id=%1 [L,R]
Note: (.*) in the rewrite rule is obsolete.
Leave the R away to do not redirect the visitor to the url (/view.php?id=%1)

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

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]