redirect subdomain url to main domain htaccess - .htaccess

I've a problem i cant figure out. People access this url:
http://www.sub.domain.net/action
but they need to be redirect to
https://www.domain.net/action/action2
I tried doing this with this line in .htaccess:
Redirect http://www.sub.domain.net/action https://www.domain.net/action/action2
But it's not working.
I only need this specific url to be redirected, not the entire www.sub.domain.net. Any advice?

Try This and check if it works for you.Change Links in the code.
Put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
# target with original URI being carried over
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
RewriteRule ^ http://www.domain.com/sub%{REQUEST_URI} [NE,R=301,L]
And for 2nd part:
# static target
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
RewriteRule ^ http://www.domain.com/sub/zero [NE,R=301,L]
Why you didn't use jquery,javascript or php to redirect onload from one page to another?
This answer is extracted from here.

Related

Redirect loop while looking for uri that does NOT contain specific string

I have an site lets say https://example.com/ and I would like to redirect every url that doesn't begins with /something to https://example.com/something/
I'm using Apache 2.4.29 (hosting) and my .htaccess looks like this.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/something(.*)$ [NC]
RewriteRule ^(.*)$ /something/ [R=302,NC,L]
My problem is that when I'm on homepage (/) or any other page I'm redirected to /something/ which is correct but when I'm on /something/ I'm still beeing redirected to /something/ and it loops until ERR_TOO_MANY_REDIRECTS error shows up.
Here is a link to htaccess tester which shows that this should work and should not redirect me to /something/ when I'm already here but it is not the case on my hosting.
I was following this and this question but without success.
With your shown attempts, please try following set of rules. Please place them on top of htaccess rules file in case you already have existing rules.
Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/?$
RewriteCond %{THE_REQUEST} !something [NC]
RewriteRule ^ /something? [R=302,NC,L]
You can try this rule with THE_REQUEST variable:
RewriteEngine On
RewriteCond %{THE_REQUEST} !\s/something [NC]
RewriteRule ^ /something/ [R=302,L]
Make sure to test it after completely clearing browser cache.
THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of other rewrite directives. Example value of this variable is GET /index.php?id=123 HTTP/1.1

Want to redirect specific page to another page using .htaccess

Hey can any one tell me how can i redirect my this page http://www.fastvpnservice.com/best-vpn-for-torrenting.html to another page http://www.fastvpnservice.com/5-best-fastest-vpn.html using .htaccess file, I would be very thankful to someone who will provide me a complete code, I just copy and paste it into my .htaccess file.
You can use:
RewriteEngine on
RewriteRule ^best-vpn-for-torrenting\.html$ 5-best-fastest-vpn.html [NC,R=301,L]
You can use the following rule to redirect the specific url to a new location :
RewriteEngine on
RewriteCond %{THE_REQUEST} /best-vpn-for-torrenting\.html [NC]
RewriteRule ^ http://www.fastvpnservice.com/5-best-fastest-vpn.html [L,R]

htaccess mod_rewrite and 301 redirect to friendly url

Now, I'm trying to write some htaccess code with mod_rewrite. I have problem with it :(
RewriteEngine On
RewriteRule ^home$ index.php?page=home
This is my code in .htaccess file. When I go to domena.com/index.php?page=home it's exactly same like domena.com/home
But, It's not friendly for google, 'cos we have double page:
domena.com/index.php?page=home
domena.com/home
It's same.
What I want to achieve? I want to user who choose domena.com/index.php?page=home redirect him to domena.com/home
Exactly, I want to on my website be exist ONLY friendly link.
Help me :(
You will need another rule to redirect old URL to new one.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
RewriteRule ^home/?$ index.php?page=home [L,NC,QSA]

301 redirect specific URLS if ?noRedirect not in URL

I'm running a wordpress installation and want to move specific feeds off-site. I've already got most of the technology down, but here's the problem. I want the following URL:
http://www.csicon.net/g/feed
to redirect to
http://feed.mesr.it/g
But if the URL comes in like this:
http://www.csicon.net/g/feed?noRedirect
I don't want it to redirect but load the original. Any thoughts?
The .htaccess file on http://www.csicon.net/ would contain:
RewriteCond %{QUERY_STRING} ^$
RewriteRule ^\/g\/feed$ http://feed.mesr.it/g [L,R=301]
Note: It has not been tested, but you get the idea.
Later Edit: Also, this can be done in PHP.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)csicon\.net$ [NC]
RewriteCond %{QUERY_STRING} !(^|&)noRedirect [NC]
RewriteRule ^([^/]+)/feed/?$ http://feed.mesr.it/$1 [L,NC,R=302]

change .htaccess of idx feed so url shows the domain name

I have idx feeds from idxbroker.com, but the url the provide is not such a clean url.
http://myrealestatewebsite.idxbroker.com/i/xxxx-xxxxx-xxxxx-xxx
Is there a way to change the url with htacess, so
when visitor type http://www.myrealestatewebsite.com/xxxx-xxxxx-xxxxx-xxx
is shows content of http://myrealestatewebsite.idxbroker.com/i/xxxx-xxxxx-xxxxx-xxx
Do i have to change my links also? a way that will benefit SEO as all are hosted in the main website http://www.myrealestatewebsite.com
Yes, try this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} /i/([^\s]+) [NC]
RewriteRule ^ /%1 [R=301,L]
RewriteCond %{REQUEST_URI} !/i/ [NC]
RewriteRule ^(.+)$ /i/$1 [L]
Once that is there you can change your links to without /i/ at front. However till the time you don't change first 301 rule will take care of it.

Resources