i want to create with htaccess that if you go to www.website1.com/page.php that you go to www.website2.com/page.php, and www.website1.com/foo/bar/index.php to www.website2.com/foo/bar/index.php redirects. How can i do that with htaccess? Example please.
If mod_rewrite is available, you can put this code into the .htaccess of www.website1.com:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?website1\.com$
RewriteRule ^(.*)$ http://www.website2.com/$1 [L,QSA,R=301]
This would redirect every page on website1.com to the equivalent on website2.com
Related
Now, I'm trying to write some htaccess code with mod_rewrite. I have problem with it :(
RewriteEngine On
RewriteRule ^home$ index.php?page=home
This is my code in .htaccess file. When I go to domena.com/index.php?page=home it's exactly same like domena.com/home
But, It's not friendly for google, 'cos we have double page:
domena.com/index.php?page=home
domena.com/home
It's same.
What I want to achieve? I want to user who choose domena.com/index.php?page=home redirect him to domena.com/home
Exactly, I want to on my website be exist ONLY friendly link.
Help me :(
You will need another rule to redirect old URL to new one.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index\.php\?page=([^\s&]+) [NC]
RewriteRule ^ %1? [R=302,L,NE]
RewriteRule ^home/?$ index.php?page=home [L,NC,QSA]
I am trying to redirect the following (respectively):
http://sub.firstdomain.com/d/(all_files_and_folders)
http://sub.firstdomain.com/d2/(all_files_and_folders)
to
http://sub.seconddomain.com/d/(all_files_and_folders)
http://sub.seconddomain.com/d2/(all_files_and_folders)
There are other files and folders under the first subdomain that I do not want redirected. Previously this was working but now it seems like Go Daddy changed something and what I had is no longer working. Here it is:
Options -Multiviews
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^stats/(.+) /dstats/count.php?statspage=$1 [L,NC,QSA]
RewriteRule ^(.+)\.deb$ /dstats/count.php?file=$1.deb [L,NC,QSA]
RewriteCond %{HTTP_HOST} ^sub\.
RewriteRule ^(d2?)/(.*)$ http://sub.seconddomain.com/$1/$2 [L,R=301]
You can ignore the RewriteRule. It is working fine. I wanted to make sure I included the entire .htaccess file just in case. My issue is with RewriteCond it seems.
The following should work:
RewriteEngine On
Redirect 301 /d/ http://sub.seconddomain.com/d/
Redirect 301 /d2/ http://sub.seconddomain.com/d2/
The above should only redirect anything in the /d/ and /d2/ folder of the sub subdomain.
EDIT: Second try
RewriteEngine On
RewriteCond %{HTTP_HOST} ^sub1\.
RewriteRule ^(d2?)/(.*)$ http://sub2.mydomain.com/$1/$2 [L,R=301]
I want to 301 redirect a subdomain to another domain with htaccess.
I want:
A: www.subdomain.domain1.se
B: subdomain.domain1.se
C: subdomain.domain1.se/anything/anything.anything#anything?anything
to redirect to:
A: www.domain2.se
B: www.domain2.se
C: www..domain2.se/anything/anything.anything#anything?anything
Also I need to know where to put the file (in subdomain directory or root directory). Best would be if I could put the htaccess file in the subdomain ddirectory if possible.
I have tried this:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^c\.domain1\.se$ [NC]
RewriteRule ^(.*)$ http://www.domain2.se/$1 [QSA,R=301,L]
I think you messing RewriteBase / in the code
regular redirect 301 work like this
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)$ http://domain2.com/$1 [L,R=301,NC]
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} subdomain\.domain1\.se$ [NC]
RewriteRule ^ http://www.domain2.se%{REQUEST_URI} [R=301,L,NE]
Reference: Apache mod_rewrite Introduction
However note that URL part after hash is not sent to web server hence cannot be handled by Apache mod_rewrite.
I have a big list of duplicate urls and i need to do some redirect
Example
www.mysite.com/mypage/name2_68.html
www.mysite.com/jjj/name2_68.html
www.mysite.com/aa/name2_68.html
www.mysite.com/5654/name2_68.html
www.mysite.com/mypage/myname87.html
www.mysite.com/6584/myname87.html
www.mysite.com/any-number/myname87.html
www.mysite.com/any_word/myname87.html
All i need to do is to redirect them to
www.mysite.com/mypage/myname87.html
www.mysite.com/mypage/name2_68.html
So all url with
www.mysite.com/anycharactere/example1.html
Will be redirect to
www.mysite.com/mypage/example1.html
This should work.
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/mypage/?
RewriteRule ^[^/]+/(.*\.html?)$ /mypage/$1 [R=301,L]
Put it in your .htaccess
RewriteEngine On
RewriteRule .*/([^/]+.html)$ /mypage/$1
I'm using the following .htaccess file to do few mod-rewrites and also redirect visitors from non-www to www. But the problem is, when someone visit http://domain.com/terms it redirects them to http://www.domain.com/document_terms.php by ignoring the 3rd line.
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^terms$ document_terms.php
RewriteRule ^privacy$ document_privacy.php
RewriteCond %{HTTP_HOST} !^www
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
Is there a way to fix this?
You just need to change the order of your rules so the www rewriting comes first.