I'm trying to redirect website A to website B. All of the sub-pages are redirecting as intended, but the home page is not. Here is a snippet of my .htaccess:
# HOMEPAGE (This one isn't working)
RewriteRule ^/$ http://www.drinkinggamezone.com [L,R=301]
# SUBPAGE (Works)
RewriteRule ^1990s-rock-power-hour/?$ http://drinkinggamezone.com/power-hours/1990s-rock? [L,R=301]
You have an unnecessary / in the first part of your rule, it should be :
RewriteRule ^$ http://www.drinkinggamezone.com [L,R=301]
Regarding index.php, just do the same (again, without /, obviously) :
RewriteRule ^index.php$ http://www.drinkinggamezone.com [L,R=301]
Try this:
RewriteCond %{HTTP_HOST} ^DomainA.com
RewriteRule ^(.*) http://DomainB.com/$1 [P]
Hope it will work.
Related
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 need to redirect anything with ?page= or ?page="" back to the homepage.
I tried RewriteRule ^/\?page=(.*)$ / [R=301,L] but it doesn't work.
Example:
http://example.com/?page= or http://example.com/?page=test or
http://example.com/?page="test"
RewriteCond %{QUERY_STRING} .
RewriteRule (.*) /404.php? [R,L]
Did the trick.
The RewriteCond part catches any query (.) and then the RewriteRule redirects it to a 404 page.
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]
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]
I try redirect all pages to new domain exclude one page with htacces.
RewriteCond %{REQUEST_URI}!^/onepage.php/
RewriteRule (.*) http://newdomain.com/$1 [R=301,L]
This is working but page onepage.php show internal error 500
You can try with either of the following in your .htaccess file:
Example 1: Check the request URI for onepage.php and redirect if it is not being requested:
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/onepage.php [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
Example 2: If onepage.php is being requested, don't do anything. Otherwise, redirect:
RewriteEngine on
RewriteRule ^onepage\.php - [L]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301,L]
As you're redirecting everything except for onepage.php, you do not need any other rules in your file. The rules above should be the only ones in there.