I'm having some issues with redirecting a clients website.
I have a site with a /uk directory that's being redirected to a uk sub-domain, Everything else redirects to a new URL
This all works fine, but they now need to access the old sites /uk/administrator directory. How can I exclude /uk/administrator from the other rules?
Here is my current set-up:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example.com\.com$
RewriteRule ^uk/(.*) http://uk.example.com/$1 [R=301,L]
RewriteEngine on
RewriteBase /
RewriteRule ^(.*)$ http://www.newexample.com/ [R=301,L]
I've been frantically Googeling for the past 30min with no luck.
Try :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example.com\.com$
#Exclude /uk/administ
RewriteCond %{REQUEST_URI} !^/uk/administrator/
RewriteRule ^uk/(.*) http://uk.example.com/$1 [R=301,L]
You can use negative lookahead:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example.com\.com$ [NC]
RewriteRule ^uk/((?!administrator/).*)$ http://uk.example.com/$1 [R=301,L]
RewriteRule ^(.*)$ http://www.newexample.com/$1 [R=301,L]
Related
I've changed the domain of wordpress and would like to redirect only EC pages.(The domains are example.)
・Old Domain -> https://old-domain.com
・New Domain -> https://new-domain.com
I want to redirect all pages from old to new, except these pages.
・shop
・product
・cart
・checkout
And I wrote those on my htaccess file.
▼Old Domain(Wanna redirect only shop, product, cart, checkout directories to New Domain.)
RewriteEngine on
RewriteBase /
RewriteRule ^shop(.*)$ https://new-domain.com/shop$1 [R=301,L]
RewriteRule ^product(.*)$ https://new-domain.com/product$1 [R=301,L]
RewriteRule ^cart(.*)$ https://new-domain.com/cart$1 [R=301,L]
RewriteRule ^checkout(.*)$ https://new-domain.com/checkout$1 [R=301,L]
▼New Domain(Wanna redirect all pages to Old Domain, excerpt shop, product, cart, checkout directories.)
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/shop/$
RewriteCond %{REQUEST_URI} !^/product/$
RewriteCond %{REQUEST_URI} !^/cart/$
RewriteCond %{REQUEST_URI} !^/checkout/$
RewriteRule (.*) https://old-domain.com [R=301,L]
Both of them do not work. It seems to redirect correctly in a moment, but immediately back to https://new-domain.com.
Please help me to solve it.
I've just solved it by myself!
The above is the correct answers I wrote on httaccess files.
▼old-domain.com
RewriteEngine on
RewriteBase /
RewriteRule ^shop(.*)$ https://new-domain.com/shop$1 [R=301,L]
RewriteRule ^product(.*)$ https://new-domain.com/product$1 [R=301,L]
RewriteRule ^cart(.*)$ https://new-domain.com/cart$1 [R=301,L]
RewriteRule ^checkout(.*)$ https://new-domain.com/checkout$1 [R=301,L]
▼new-domain.com
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(^/shop/)
RewriteCond %{REQUEST_URI} !(^/product/)
RewriteCond %{REQUEST_URI} !(^/cart/)
RewriteCond %{REQUEST_URI} !(^/checkout/)
RewriteCond %{REQUEST_URI} !(^/checkout/order-received/)
RewriteRule ^$ https://old-domain.com/ [R=301,L]
I want to redirect all pages to a new website with the same site structure, e.g. olddomain.com/123.html to newdomain.com/123.html, this works perfectly fine with:
RewriteEngine On
RewriteCond %{REQUEST_URI} (.*)
RewriteRule ^(.*)$ https://newdomain.com$1 [L,R=301]
But i want the Frontpage to be redirected to newdomain.com/landingpage, i tried the following and it isn't working.
RewriteEngine On
Redirect 301 / https://newdomain.com/landingpage
RewriteCond %{REQUEST_URI} (.*)
RewriteRule ^(.*)$ https://newdomain.com$1 [L,R=301]
Can someone help me with this?
You can use this :
RewriteEngine On
#redirect homepage to a specific location on new domain
RewriteRule ^/?$ https://newdomain.com/landingpage [L,R=301]
#redirect everything else from old domain to new
RewriteCond %{REQUEST_URI} (.*)
RewriteRule ^/?(.*)$ https://newdomain.com/$1 [L,R=301]
I have several domains pointed to my hosting. Suppose I have ex1.com, ex2.com, ex3.com pointed to my hosting. Now ex2.com is hosted on another hosting. Now I want to add a redirect rule on the htaccess file so that I can redirect ex1.com to ex2.com. What will be the code? I tried the code below but no luck :-
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ex1.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.ex1.com [NC]
RewriteRule ^(.*)$ http://www.ex2.com/$1 [L,R=301,NC]
Can anyone please inform me what I have to do?
You require Redirect 301:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !newdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [L,R=301]
This is useful when you use www.newdomain.com as your new domain name. If the domain is different, then use:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^olddomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.olddomain\.com$
RewriteRule (.*)$ http://www.newdomain.com/$1 [R=301,L]
</IfModule>
Obviously replace olddomain and newdomain with the correct domains.
Here is the sample found in numerous posts
RewriteEngine On
RewriteCond %{HTTP_HOST} ^yatko.com[NC]
RewriteRule ^(.*)$ http://www.yatko.com/$1 [R=301,L]
*wanted to rewrite the main domain only leaving the addon/parked domains unaffected
- the sample above does not work for some reason.
updated
did you set RewriteEngine On on top of the .htaccess ? :
RewriteEngine On
RewriteCond %{HTTP_HOST} !^yatko\.com [NC]
RewriteRule ^(.*)$ http://www.yatko.com/$1 [R=301,L]
I needed to redirect my od domain to a new one. All paths are same on both domains except the front page, which needed to be redirected from www.mydomain.com to www.mydomain2.com/newpath. I googled and came up with this code which works. My question is if it is valid and if all pageranks will be transfered without problems. Thank you
RewriteEngine on
RewriteCond %{HTTP_HOST} domain\.com [NC]
RewriteCond %{REQUEST_URI} ^/$
Rewriterule ^(.*)$ http://www.domain1.com/folder/ [L,R=301]
RewriteRule ^(.*)$ http://www.domain1.com/$1 [L,R=301]
Your code should work but it can be fine tuned a bit. Please consider this refactored code:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
Rewriterule ^$ http://www.domain1.com/folder/ [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ http://www.domain1.com%{REQUEST_URI} [L,R=301]