I have a list of 301 Redirects like this inside htaccess:
Redirect 301 /oldpage1.php http://www.domain.com/newpage1.php
Redirect 301 /oldpage2.php http://www.domain.com/newpage2.php
Redirect 301 /oldpage3.php http://www.domain.com/newpage3.php
...
Now these pages shall be redirected only for a certain domain (there are other domains now pointing to the same location like www.domain.com).
E.g. www.domain.com/oldpage1.php shall be redirected, but www.sub.domain.com/oldpage1.php not.
So whats the way to apply these redirects only for www.domain.com?
Thanks.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^oldpage1\.php/?$ newpage1.php [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^oldpage2\.php/?$ newpage2.php [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteRule ^oldpage3\.php/?$ newpage3.php [L,R=301]
PS: If you have several rules like above then it is much better to use RewriteMap.
Related
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 am trying to redirect site a to site b with same url structures. My htaccess is
Redirect 301 / http://www.siteb.com/
RewriteRule ^(.*)/(.*)/(.*)$ index.php?video=$1&id=$2&words=$3
RewriteRule ^videos/(.*)$ index.php?videos=$1
However, on the redirected site, it adds additional variables. For example;
siteA.com/y/T5INF08ZEdA/Miranda-Kerr-In-Hot-Water-with-Orlando-Bloom
siteB.com/y/T5INF08ZEdA/Miranda-Kerr-In-Hot-Water-with-Orlando-Bloom?video=y&id=T5INF08ZEdA&words=Miranda-Kerr-In-Hot-Water-with-Orlando-Bloom
What is the correct way to 301 redirect with same url structures ?
It is because of the 2 main problems in your code:
Mixing of mod_alias and mod_rewrite rules.
Not using L flag in mod_rewrite rules and that is causing multiple rules firing on same URL.
I would suggest you to stick with mod_rewrite only and keep your .htaccess like this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)sitea\.com$ [NC]
RewriteRule ^ http://www.siteb.com%{REQUEST_URI} [L,R=301]
RewriteRule ^videos/(.*)$ index.php?videos=$1 [L,QSA,NC]
RewriteRule ^([^/]+)/([^/]+)/(.*?)/?$ index.php?video=$1&id=$2&words=$3 [L,QSA]
I want this page:
http://mystore.com/Login.aspx?ReturnUrl=%2fPages%2fHome%2fUser%2fWish-list.aspx
to
http://mystore.com/en/ukeurope/home
So, I try to write a 301 redirection rule like this:
RewriteRule ^Login.aspx$ en/ukeurope/home? [R=301,L]
but when I want to try this redirection.
It gives me 404 not Found.
P.S. I don't want another one that is
mystore.com/Page/Login.aspx
to be redirected by this 301 redirection rule
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+Login\.aspx?ReturnUrl=\%2fPages\%2fHome\%2fUser\%2fWish-list\.aspx [NC]
RewriteRule ^ /en/ukeurope/home? [R=302,L]
The crawling properties of site showing
http://www.abc.com/http://www.abc.com/index.php?option=com_toys
http://www.abc.com/http://www.abc.com/index.php?option=com_article
http://www.abc.com/http://www.abc.com/index.php?option=com_play&view=category&vid=10
The site been crawled like this, with errors coming in as duplicate url. Correct url is
http://www.abc.com/index.php?option=com_toys
http://www.abc.com/index.php?option=com_article
http://www.abc.com/index.php?option=com_play&view=category&vid=10
is there any way to 301 redirect
i tried using
RewriteCond %{REQUEST_URI} ^.*/http://www.abc.com.*$
RewriteRule .* index.php [R=301,L]
But its not achieving the desired as redirecting to http://www.abc.com/index.php
How to redirect through htaccess from incorrect url to correct url sttructure off site
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+http://.+?(/index\.php\?[^\s]+) [NC]
RewriteRule ^ %1 [R=301,L,NE]
Try this code :
RewriteEngine On
RewriteRule ^http://www.abc.com/index.php /index.php [QSA, R=301]
Question is pretty simple I guess, but I fail to do this myself.
I have a website on http://website.com and want to 301 redirect ALL requests on www.website.com to http://website.com/ but make sure all directories and filenames stay the same (so not all requests end up at the homepage).
So whatever people may type (like www.website.com/something.here) should 301 redirect to website.com/something.here
How to do this?
Add the below to your .htaccess file. Should do the trick.
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
This requires that the rewrite engine is on...
<IfModule mod_rewrite.c>
############################################
## enable rewrites
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
</IfModule>