I need some help on mod rewrite 301 , to redirect my old website address to the new address ,
here is my scenario
ive www.domain1.com/page1/
want to be redirect to domain2.com/page1/
ive to replace all request goes to domain1 with domain2 and keep the page after .com
so watever was after .com should be the same just replace domain1 with domain2 .
anyone can help me with this
Regards
You may want to make sure UseCanonicalName is off, lest apache replace hostnames with the site's ServerName.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.domain1\.com$ [NC]
RewriteRule ^(.*)$ http://domain2.com$1 [R=301]
When redirecting from one domain name to another, you should also take the www prefix into account. This Rewrite rule will match the old domain name with or without the www prefix.
RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com$ [NC]
RewriteRule ^(.*)$ http://newdomain.com/$1 [R=301]
or if you prefer to keep the www prefix, substitute this RewriteRule:
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301]
Related
I have this .htaccess rule
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
This covers the parent domain but not the subdomain.
My subdomain has the same public folder as of parent domain.
example.com is redirected to https://example.com
But subdomain.example.com is not redirected to https://subdomain.example.com
As I said above that both points to same public folder so I want the above rule to handle both.
But I don't want to write my domain or subdomain name in htaccess rule. It shall cover any domain and any subdomain
You can do this with the HTTP_HOST header:
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
So you get it from the request rather than using the server name for the virtual host. Also simplifying the regex since you’re not using the capture.
Goto your subdomain folder
Create .htaccess file in this folder
and paste this code:
just copy and paste this code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I have two domains, let's say example.com and example.tld. But I want that users always get to the .tld domain. I want to use .htaccess and have tried
RewriteEngine on
RewriteRule ^(.*)$ http://example.tld/$1 [R=301,L,QSA]
When I open example.com, it redirects to example.tld. But when I open example.tld I get an error
This webpage has a redirect loop
How do I have to modify the redirection statement?
So you will need a RewriteCond to ensure that the subsequent RewriteRule is only applied when the requested HTTP_HOST was example.com.
RewriteEngine On
# Apply the rule if the host does not already match example.tld
RewriteCond %{HTTP_HOST} !^example\.tld$
RewriteRule (.*) http://example.tld/$1 [L,R=301,QSA]
Note that when using [R], the [QSA] is already implicit. You don't actually need to add it here but it doesn't hurt.
The above would redirect any domain other than example.tld into example.tld. If you added a third domain which you did not want to redirect (redirecting only example.com), instead of the negative match in RewriteCond, you could use a positive match for that domain only.
RewriteCond %{HTTP_HOST} ^example\.com$
RewriteRule (.*) http://example.tld/$1 [L,R=301,QSA]
I have been trying to redirect old pages for my old site to the corresponding new ones with permanent redirect.
as well as redirecting www.example.com to example.com
I dont seem to able to do both on the same time
at the moment redirects works for correct links from ex www.example.com/correctlink to example.com/correctlink
but only example.com/Info.aspx is redirected to example.com/about-magento-demo-store and NOT www.example.com/Info.aspx
*Update
I want to remove www. AND redirect 40-50 specific adress to new specific adresses. My problem is that the redirect only works if google has saved the old link without Www. IF google has stored a link including www. then my redirect Redirect permanent example.com/tabid/61/CategoryID/13/ProductID/64/Default.aspx /index.php/solpaneler/re does not function –
*Update
my htaccess looks a bit like this
(with a few lines in the end that where present before I started editing)
(i also tried to ad a line Redirect permanent http://www.example.com/Info.aspx http://example.com/about-magento-demo-store but it does not function)
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com
RewriteRule ^(.*)$ http://example.se/$1 [R=301,QSA,L]
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%2://%1%{REQUEST_URI} [L,R=301]
Redirect permanent /Info.aspx /about-magento-demo-store
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteRule .* index.php [L]
Just use rewrite rules for everything. Rewrite rules and Redirect don't always mix well.
RewriteRule ^Info\.aspx$ /about-magento-demo-store [L,R=301]
I've had the same problem a looooooooong time ago. Here's a sample of my rewriterules:
# If domain name doesn't end with .com redirect to .com:
RewriteCond %{HTTP_HOST} (.*)\.(fr|net|org|eu) [NC]
RewriteRule (.*) http://%1.com$1 [R=301,L]
# If domain name without "www", add them:
RewriteCond %{HTTP_HOST} ^mydomainname\.(fr|com|net|org|eu) [NC]
# Ca signifie forcément que c'est sans www => forcer redirection :
RewriteRule (.*) http://www.mydomainname.%1$1 [QSA,R=301,L]
NB: Put this on the top of your rewrite rules, because it should be processed before anything else so that you are sure your domain name always begin with "www"
Note that it redirects mydomainname only if it's "empty" i.e. nothing behind. It won't touch URLs like http://abc.mydomainname.com and it won't touch URLs like http://abc.def.mydomainname.com
Tell me if it works.
I have a simple .htaccess which redirect non www to www domain
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
What I need to do is to exclude the IP calling from this redirect.
In other words I need that if someone call site by IP then it won't be redirected to www domain, it will call the IP itself and visitor can navigate all the site links without the 301 redirect. This means he will still navigate the site through the IP.
Try
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]
It looks to see if the host does not start with www and if so it redirects to the www URL. It won't match the IP address or any other subdomains (i.e. test.example.com)
I am using apache 2.2 on a windows OS ,
I need to redirect non www urls to www urls , i checked online , and found this seems to be working for many
RewriteCond %{HTTP_HOST} ^example\.co\.uk [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [R=301,L]
But if i use the same rewrite rules i get www urls with a dot in the end :
ex :
http://example.com/test redirects to
http://www.example.com.
$1 is "." and its failing to add all params
Ok!
you put this on you .htaccess file:
RewriteCond %{HTTP_HOST} ^mysite\.local [NC]
RewriteRule ^(.*)$ mysite.local/$1 [R=301,L]
it means if host equals to mysite.local (end of host not mentioned!) so every url redirects to directory mysite.local!
You should use this:
RewriteCond %{HTTP_HOST} !^www\.mysite\.local
RewriteRule (.*) http://www.mysite.local/$1 [L,R=301]
So every URL that host IS NOT equal to www.mysite.local will redirect to this one! but remember if you want to create subdomain, PUT DOCUMENT ROOT OF THIS SUBDOMAIN OUT OF WWW.MYSITE.LOCAL DOCUMENT ROOT! (it's better!)