htaccess RewriteRule for new domain - .htaccess

have some problems with my .htaccess file. I have two domains, old one and new one. i want to redirect user to the new site, when they visit the old domain.
Example:
if they visit: "olddomain.com" then they should get redirected to "newdomain.com". this is actually not that hard to code BUT i want some special redirects too. if someone trys to visit "olddomain.com/service.html" then i want redirect the user to "newdomain.com/whatwedo.hml".
And if someone trys to visit "olddomain.com/test/hello/text.html" then i want to redirect him to "newdomain.com/something/hello.html".
i have a list of 20 specific links i want to redirect.
what i've tried so far:
RewriteEngine On
RewriteCond %{HTTP_HOST} (www\.)?olddomain.com/service.html
RewriteRule (.*) http://www.newdomain.com/whatwedo.hml [R=301,L]
RewriteCond %{HTTP_HOST} (www\.)?olddomain.com
RewriteRule (.*) http://www.newdomain.com/ [R=301,L]
with this code every visit on olddomain.com/whatever will redirect to "newdomain.com"
can someone help me?
thank you :)
Greetings

%{HTTP_HOST} will contain only the domain name used in browser address bar (olddomain.com) but not the URI (/service.html), so your first condition will never be matched. Try this:
RewriteCond %{HTTP_HOST} (www\.)?olddomain.com
RewriteRule ^service\.html http://www.newdomain.com/whatwedo.hml [R=301,L]

Related

How to add .htaccess URL mask so that specific pages are shown to be under subdomain

I got a site with some pages:
http://example.com/myuglyurl.php?id=11
http://example.com/myuglyurl.php?id=12
http://example.com/myuglyurl.php?id=13
and, just for some pages, I want my users to see in their browsers that they are in subdomain, for example:
http://example.com/myuglyurl.php?id=11
http://mynewsubdomain.example.com/myuglyurl.php?id=12
http://example.com/myuglyurl.php?id=13
Subdomain exists and when user directly tries to visit subdomain, I'll redirect them to specific page, that is no problem. But the URL mask I cannot make.
I've tried all kinds of .htaccess tricks, but as I am a complete stranger to .htaccess, I cannot manage to do it.
I've tried:
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteCond %{QUERY_STRING} (^|&)id=12($|&)
RewriteRule ^myuglyurl\.php$ http://mynewsubdomain.example.com/myuglyurl.php?%{QUERY_STRING}
But I get blank page with message: File not found.
Please use this following.
Redirect and keep everything after the URL
Visit yourdomainA.com/page and it will show the content from yourdomainB.com/page
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomainA.com
RewriteRule ^(.*) http://www.yourdomainB.com/$1 [P]
For more details, please refer to this link - https://www.brontobytes.com/knowledgebase/202/htaccess-URL-Masking-Examples.html

Rewrite rule for magento store view

i have a question about .htaccess redirection rule. Namely, i have two store views in magento: english and swedish. I want to write rule in .htaccess that when user type in this address in browser url bar www.example.com/se to be redirected to https://example.com/se/
Can someone help me od give me some pointers for this problem?
Thanks
you can write like this
RewriteCond %{HTTP_HOST} =www.example.com
RewriteRule (.*) http://example.com/$1 [R=302,L]

How to add correct 301 redirect to specific page

I am searching for the correct code to add in the htaccess file for this situation:
At springintveld.nl there was an old Joomla!site. That site is deleted. The domain is moved and set as Domainpointer in Direct Admin of kindcentrumschalkhaar.nl
For the organisation Spring in t Veld, I have created a special part in the menu of kindcentrumschalkhaar.nl
So when a visitor is browsing to springintveld.nl, he must be redirected to : kindcentrumschalkhaar.nl/peuteropvang
I hoped it could work with this code:
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} ^springintveld.nl$ [OR]
RewriteCond %{HTTP_HOST} ^www.springintveld.nl$
RewriteRule ^/?$ “http://www.kindcentrumschalkhaar.nl/peuteropvang” [R=301,L]
</IfModule>
But with this code the redirection is still to the mailpage of kindcentrumschalkhaar.nl
I hope someone can help to give me the correct code.

htaccess rewrite rule for subdomain results to redirect loop

Below is my htaccess config
RewriteEngine On
# if the domain starts with "apply."
# i.e. apply.domain.com
# redirect to application URI
RewriteCond %{HTTP_HOST} ^apply\. [NC]
RewriteRule !^formwizard /formwizard/apply [R=301,L,NC]
I have tried it, and when I go to http://apply.domain.com/ it successfully redirects to http://apply.domain.com/formwizard/apply.
My problem is, once it redirects to that URI, it goes to a redirect loop.
Can anyone please help hit me what is wrong with my config?
Background:
I have 3 subdomains: www.domain.com, apply.domain.com, and admin.domain.com. It all references to the same source codes and just managed by my htaccess.
Once the person goes to apply.domain.com, it should be redirected to the application page which is /formwizard/apply.
PS. I don't want to depend too much on the backend codes because I believe this is a server config problem.
Thanks in advance!
If there are more rules then this rule might be getting impacted by them. Modify this rule to this:
RewriteCond %{HTTP_HOST} ^apply\. [NC]
RewriteCond %{THE_REQUEST} !/formwizard/ [NC]
RewriteRule ^ /formwizard/apply [R=301,L,NC]
Also make sure this is very first rule below RewriteEngine On line.

URL Rewriting for url with countrycode

I am writing a multi language website. Therefore I would like some help with a URL rewrite problem.
Case:
When someone visits www.example.com without adding a country code (nl, en, de) the htaccess redirects the visitor to www.example.com/nl/ i.g.
RewriteRule !(nl|en|de)(.*).* /nl/ [R=301,L]
The website is renewed and has got many url's directing to the website (google, forums). i.g. www.example.com/oldpage-nomore.html. What I would like is the following; the htaccess should detect that the request uri doesn't contain nl,en or de and should redirect to pagenotfound.php. RewriteRule ^(.*)\.html /public/oldurl?section=nl&notfound=$1$2&basehref=true&%1 [PT,L] the problem with this Rewrite rule is: all files ending in .html are being redirected.
What I am looking for is the following:
When someone visits www.example.com and no request uri is entered this should redirect to www.example.com/nl/
When there is a requested uri and this doens't contain a countrycode (nl|en|de) than redirect to pagenotfound.php
I tried the following but it doens't work:
RewriteCond %{REQUEST_URI} !^(nl|en|de)$
RewriteRule ^([a-z]{2})/(.*)\.html$ /pagenotfound.php?page=$2 [L,R=404]
I hope someone can help.
Thank you in advance.
Try to place this .htaccess file at the server root folder:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/?$
RewriteRule ^.*$ /nl/ [R]
RewriteCond %{REQUEST_URI} !^/(nl|en|de)
RewriteRule ^.*/(.*)\.html$ /pagenotfound.php?page=$2 [L,R=404]
(you probably made several mistakes, I tried to fix them)
I'm not sure with the first RewriteCond %{REQUEST_URI} regular expression - maybe remove the question mark or slash, I don't now... can't test now.

Resources