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]
Related
My .htaccess file includes this, which allows the URL structure in my ExpressionEngine site to function:
RewriteRule ^(.*)$ /index.php?/$1 [L]
However, it is interfering with what I'm trying to do here, redirecting an old page:
Redirect 301 /old-url/ /
This is what I see in my browser address after I load the /old-url/ address:
https://www.domain.test/?/old-url/
If I take out the RewriteRule, my Redirect 301 works, but all the navigation in the site breaks. Is there some way for me to make an exception where I want to redirect old URLs? I have inherited someone else's work in this case.
Edit: here is my entire .htaccess file content:
RewriteEngine On
Redirect 301 /in-loving-memory-of-our-partners /
Redirect 301 /in-loving-memory-of-our-partners/ /
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R,L]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteRule ^sitemap\.xml$ /sitemap/xml [NC,L]
RewriteCond $1 !^(assets|emergency|portalimages|images|system|themes|test|AUL|swfs|favicon\.ico|robots\.txt|index\.php) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteRule ^(.well-known) - [L]
I have two domains, autodromodifranciacorta.it and franciacortacircuit.com both pointing to the same website hosted on this IP address: 94.23.64.40.
Now i want all the content to be under one single domain, so i decided to 301 redirect all the traffic from franciacortacircuit.com to autodromodifranciacorta.it
Here is my .htaccess file:
# BEGIN WordPress
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
# Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
The redirect is not working and i have no clue why, because the syntax looks correct to me.
The .htaccess file is processed, because if i put a typo in it, i get server error.
Wha'ts wrong with it?
Your second http_host condition is wrong and it never matches if the current host is franciacortacircuit.com, You need to use an OR condition to match against 2 diffrent hosts.
#Redirect Entire Site to New Domain
RewriteCond %{HTTP_HOST} ^franciacortacircuit\.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.autodromodifranciacorta\.it$ [NC]
RewriteRule ^(.*)$ http://autodromodifranciacorta.it/$1 [R=301,L]
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]
i have developed a website using codeigniter. Previously the site had a long URL structure so i have made them shorter in the new website.
Although i used the redirect directive in htaccess it gives me a 404 error. I have removed all the old controllers and functions.
below is a few lines from htaccess (there are many urls redirecting to new ones)
RewriteEngine On
# Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
#RewriteRule ^([^_]*)_(.*)$ /$1-$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Redirect 301 /payments/charity_and_donations/paid http://www.mysite.com/charity
Redirect 301 /outwards/office_furniture/damaged http://www.mysite.com/office_assets
Redirect 301 /funding/business_and_person/inward http://www.mysite.com/funds
can someone tell me why it is not redirecting from the old to the new and what am i doing wrong?
You need to have your redirecting happen before you route URIs to /index.php. Also, since Redirect is part of mod_alias and your other redirect/routing rule is mod_rewrite, the URI is being processed twice when it's not supposed to. You should just use mod_rewrite and add the rules to the beginning:
RewriteEngine On
# Redirect non-www urls to www
RewriteCond %{HTTP_HOST} ^mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
RewriteRule ^payments/charity_and_donations/paid http://www.mysite.com/charity [R=301,L]
RewriteRule ^outwards/office_furniture/damaged http://www.mysite.com/office_assets [R=301,L]
RewriteRule ^funding/business_and_person/inward http://www.mysite.com/funds [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
Try the below code, this works perfectly for me
RewriteCond %{HTTP_HOST} !^www\.yoursite\.com$ [NC]
RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]
Ok so i have an admin folder in a site that i am working and what i need is when someone enters
http://admin.teamfocususa.org/
in their browser then they get redirected to the admin folder
here is my htaccess
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^teamfocususa.org [NC]
RewriteRule ^(.*)$ http://www.teamfocususa.org$1 [L,R=301]
RedirectMatch 301 ^/admin/(.*)$ http://admin.teamfocususa.org/$1
Redirect http://admin.teamfocususa.org /admin
this part is not working
Redirect http://admin.teamfocususa.org /admin
any ideas on how to make this part work ...when i visit http://admin.teamfocususa.org is the home page and not the admin folder as i thought....FYI this is a shared host and I dont have access to the vhost to fix this the way i know
Try adding a RewriteRule matching on requests to / of admin.teamfocususa.org.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^teamfocususa\.org^ [NC]
RewriteRule ^(.*)$ http://www.teamfocususa.org$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?teamfocususa\.org [NC]
RewriteRule ^admin(.*) http://admin.teamfocususa.org/$1 [L,R=301]
# Not needed
#RedirectMatch 301 ^/admin/(.*)$ http://admin.teamfocususa.org/$1
# Added = requests to http://admin.teamfocususa.org/
# Redirected into http://admin.teamfocususa.org/admin
# --OOPS fixed RewriteCond - was typo RewriteRule
RewriteCond %{HTTP_HOST} ^admin\.teamfocususa\.org$ [NC]
RewriteRule ^$ admin/ [L,R=301]
# To hide /admin on admin.teamfocususa.org
# use this instead of the above group...
RewriteCond %{HTTP_HOST} ^admin\.teamfocususa\.org$ [NC]
RewriteRule ^$ admin/ [L]
# Not needed
#Redirect http://admin.teamfocususa.org /admin
I do not think you want to do a Redirect, but a simple RewriteRule to show the admin folder for the domain admin.teamfocususa.org
RewriteEngine On
RewriteBase /
# If not admin.teamfocususa.org and in /admin folder, redirect to admin.teamfocususa.or
RewriteCond %{HTTP_HOST} ^admin.teamfocususa.org [NC]
RewriteRule ^/admin/(.*)$ http://admin.teamfocususa.org/$1 [L,R=301]
# If domain is admin.teamfocususa.org, show files from admin folder
RewriteCond %{HTTP_HOST} admin.teamfocususa.org [NC]
RewriteRule (.*)$ /admin$1 [L]
# if domain is teamfocususa.org, redirect to www.teamfocususa.org
RewriteCond %{HTTP_HOST} ^teamfocususa.org [NC]
RewriteRule ^(.*)$ http://www.teamfocususa.org$1 [L,R=301]
UPDATE: My domain checks were wrong, try this updated version