i'm trying to write a decent .htaccess for my website, without success.
My problem is that i want to redirect only some page to another page of another domain. All other requests must be redirected to / other domain.
I give you an example for more clarity:
I would like to redirect only:
www.foo.com/test_a.php => www.bar.com/newcategory/newpage
www.foo.com/another_page.php => www.bar.com/anothernewcategory/anothernewpage
all other request must be redirected to www.bar.com
Example:
www.foo.com/some_another_page_not_listed_above => www.bar.com
This is my .htaccess, but it don't works:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^/test_a.php
RewriteRule www.bar.com/newcategory/newpage/ [NC,L,R=301]
RewriteCond %{HTTP_HOST} ^/another_page.php
RewriteRule www.bar.com/anothernewcategory/anothernewpage/ [NC,L,R=301]
RewriteCond %{HTTP_HOST} ^/
RewriteRule https://www.bar.com/ [L,R=301]
Rule 1 and 2 works. Rule 3 no. For example if i go to www.foo.com/test_page i don't be redirected.
Where i wrong?
Can you please try this?
RewriteEngine On
RewriteRule ^test_a.php http://www.bar.com/newcategory/newpage/ [NC,L,R=301]
RewriteRule ^another_page.php http://www.bar.com/anothernewcategory/anothernewpage/ [NC,L,R=301]
RewriteRule ^ https://bar.com [L,R=301]
Related
I am redirecting
xyz.com to user.xyz.com.
But I can't redirect user.xyz.com/anythingelse.
Here is my .htaccess code
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(^.*)\.xyz.com
RewriteRule (.*) shop.php?username=%1
I think your RewriteCond should be like this:
RewriteCond %{HTTP_HOST} ^xyz\.com
Because you want to apply the rule only to the domain xyz.com, and not any subdomain.
The rule becomes:
RewriteRule ^(.*) http://user.xyz.com/$1
This redirects every page to the same page of the new website.
EDIT:
RewriteCond %{HTTP_HOST} ^user\.xyz\.com$
RewriteRule ^/?$ https://user.xyz.com/anypage.php
This allows you to access from the homepage (with or without the last "/") the page https://user.xyz.com/anypage.php
i am trying to auto 301 redirect from domain.com to domain.com/v2
ive tried this code
RewriteCond %{HTTP_HOST} ^www.domain.com [NC]
RewriteRule ^$ /v2/ [NC,L]
also tried
Redirect 301 / /v2/
i get the error 'site has tried to redirect you too many times'
is there any way to do this?
thanks for any help
Untested but this should redirect both domain.com and www.domain.com to the v2 subfolder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ v2 [L]
You need to replace example.com with your actual domain because of posting restrictions.
I suppose you have an endless redirect because you are not matching the end of the domain string with $. Redirection should only take place at the root domain.
you can use a write rule with ^$ representing the root of the site and rewrite it to the selected folder
RedirectMatch ^/$ /v2/
it redirects the root and only the root URL.
or also you can use
RewriteEngine On
RewriteRule ^$ /v2[L]
If you want external redirection(301) you can use R flag
RewriteRule ^$ /v2[L,R=301]
Another way to use it with RewriteEngine
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example\.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
RewriteRule ^$ v2 [L]
Original Answers
I hope I've helped
I have a domain foo.tech.
I want to use a new domain footech.io instead.
The redirect also has to make sure all the URLs work.
E.g foo.tech/bar goes to footech.io/bar
Here is my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^foo.tech [NC]
RewriteRule ^(.*) http://footech.io/$1 [R=301,L]
For some reason, it decides to add /html at the end of my domain.
So now if I visit foo.tech it will redirect to footech.io/html
If I visit foo.tech/bar it will redirect to footech.io/html/bar
Please help.
Update:
I think the /html comes from the $1
I've tried to make the rewrite rule as follows:
RewriteRule ^(.*) http://footech.io/$1/$1 [R=301,L]
going to foo.tech leads to footech.io/html//html/
going to foo.tech/bar leads to footech.io/html/bar/html/bar
final update:
I made it work now using this:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^foo.tech [NC]
RewriteRule ^html/(.*) http://footech.io/$1 [R=301,L]
This seems to fix it
RewriteEngine On
RewriteCond %{HTTP_HOST} ^foo.tech [NC]
RewriteRule ^html/(.*) http://footech.io/$1 [R=301,L]
Wondering if you can help me?
I'm working on a site at the moment, and the following is in the .htaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.co.uk [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]
RewriteRule ^$ http://www.example/folder-name [R=301,L]
As I see it, this works in the following manner:
root domain rewrites using 301 to www. and then an additional 301 redirect to the /folder-name.
Ideally, I'd like to remove the middle redirect (i.e from root domain to www. and keep just the redirect from root domain to /folder-name.
NB. there is a subdomain, let's call that products.example.co.uk - and access would be needed here.
Is this possible? my .htaccess skills are not particularly tight so any help gratefully received!
This should work:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.co.uk$ [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/folder-name/$1 [L,R=301]
Ideally, I'd like to remove the middle redirect (i.e from root domain to www. and keep just the redirect from root domain to /folder-name.
This should do it :
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?example.co.uk [NC]
RewriteRule ^((?!folder).*)$ http://www.example.co.uk/folder/$1 [L,R=301]
I need to have a .htaccess redirect.
If I go to example.bla.org
I want it to redirect to bla.org/example
EXCEPT: It must keep the subdomain url can needs to be dynamic.
Ex: example.bla.org/apple -> bla.org/example/apple
I have tried almost every method like this one:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^examples.website.org [NC]
RewriteRule ^/(.*)$ /examples/$1 [L]
Please help, thanks!
You're pretty close, try this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.website.org [NC]
RewriteRule ^(.*)$ http://website.org/example/$1 [L]
If you want to do a 301 redirect for SEO etc, add R=301 to the rewrite :
RewriteRule ^(.*)$ http://website.org/example/$1 [R=301,L]