Replace part of URL using .htaccess - .htaccess

I have a case like this :
http://example.com/
http://example.com/test/
http://example.com/auth/
http://example.com/auth/login
http://example.com/auth/forget_password
I need to change example.com into my IP (1.1.10.7) when user accessing path that containing auth.
The results I need are:
http://example.com/ => http://example.com/
http://example.com/test/ => http://example.com/test/
http://example.com/auth/ => http://1.1.10.7/auth/
http://example.com/auth/login => http://1.1.10.7/auth/login
http://example.com/auth/forget_password => http://1.1.10.7/auth/forget_password
I tried several times from reading on another StackOverflow question, but still not resolved.
Can anyone help?

You can use this rule in your site root .htaccess:
RewriteEngine On
RewriteCond %{HTTP_HOST} !=1.1.10.7
RewriteRule ^auth/ http://1.1.10.7%{REQUEST_URI} [L,NC,NE,R=301]

Related

Redirect every URL to new domain, including subdomains (via htaccess)

I'm doing a website migration and need to redirect all URLs, including subdomains, to the new root domain.
So, for example:
old-domain.nl/example => https://www.new-domain.nl
www.old-domain.nl/example => https://www.new-domain.nl
http://www.old-domain.nl/example => https://www.new-domain.nl
And also:
subdomain.old-domain.nl/example => https://www.new-domain.nl
anothersubdomain.old-domain.nl => https://www.new-domain.nl
This is what I got so far, but sadly it is not working:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(.*)\.old-domain\.nl$ [NC]
RewriteRule ^(.*)$ https://www.new-domain.nl/ [R=301,L]
Any help would be great :D !

htaccess redirect with parameters and ports

I need to redirect through a htaccess file from url1 to url2 with parameters.
Example:
http://www.sensotec.be:8081 => http://activation.sensotec.be:8081
http://www.sensotec.be:8081/lpweb/login.aspx => http://activation.sensotec.be:8081/lpweb/login.aspx
I know there are a lot of cases like this, but I just don't get it.
This rule should work for your case, it will keep everything after the website url, even the port:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SERVER_PORT} ^8081$
RewriteRule ^(.*) http://activation.sensotec.be%{REQUEST_URI} [R=301,NC]
Here's a working example.

Htaccess: showing same page on second domain with simplified url structure

This should be easy, but it really isn't.
I want to accomplish this:
http://finaldomain.com/PAGENAME is the url I would like
to use.
http://subdomain.generaldomain.com/index.php?/static-parameter/PAGENAME is what the server needs to render the page
A mirroring with htaccess is what I am looking for. Not a redirect.
Can this be done?
Thanks in advance,
Diederik
Try this .htaccess in your document root.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?finaldomain\.com$ [NC]
RewriteRule ^(.*)$ http://subdomain.generaldomain.com/index.php?/static-parameter/$1 [L]
This would redirect
http://www.finaldomain.com/file.php => to =>
http://subdomain.generaldomain.com/index.php?/static-parameter/file.php
http://finaldomain.com/subfolder/file.php => to =>
http://subdomain.generaldomain.com/index.php?/static-parameter/subfolder/file.php

htaccess redirect multiple domains to central domain

Hi if have 3 domain names with a dns that point at one central site with trough a central htaccess file.
I would like to redirect the site by dns to the central site + subdirectory containing the domain name.
for example:
testsite1.com => thesite.com/testsite1/
testsite2.com => thesite.com/testsite2/
testsite3.com => thesite.com/testsite3/
my idea
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www.bla1.com$ [AND]
RewriteCond %{HTTP_HOST} !^bla1.com$
RewriteRule ([^.]+)\.com(/[*]) http://bla2.com/$1/$2 [R=301,L]
The thing is, RewriteRule is not applied to a HTTP_HOST, only on a REQUEST_URI.
So You can do this:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^(www\.)?example.com$
RewriteRule (.*) http://example.com/%{HTTP_HOST}/$1 [L,R,QSA]
Note however, that ".com" will not be stripped from the hostname that is passed in the new path
Btw, "301" is "Moved Permanently". I am not sure You want that, but anyway, it is a common good practice to first use 302 status when redirecting until you're done testing and everything is finalized

Map multi domain only use htaccess

I'm Vietnamese so my english is not good.
I have problem for my cms.
I want to map sub domain to as link via htaccess
Example:
I have links as
?user=example&op=value => example.domain.com/value/ and
domain.com/?user=example1&op=value1 => example1.domain.com/value1/ or
domain.com/?user=example2&op=value2 => example2.domain.com/value2/
..... ....
and many.
I'm using shares hosting so i can't edit file http.config or any one I'm sorry because my English.
Thank all
Try adding the following to the .htaccess file in the root directory of your domain.com site.
RewriteEngine on
RewriteBase /
#if its domain.com
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
#capture the user and op query string values
RewriteCond %{QUERY_STRING} (^|&)user=([^&]+)&op=([^&]+)(&|$) [NC]
#and redirect to subdomain with appropriate value
RewriteRule ^ http://%2.%{HTTP_HOST}/%3/? [L,R=301]

Resources