I'm needing help with setting up the rewrite rules for my site.
I have one rule set up so it adds www. to my site, but I also have a mobile site that starts with m. and don't know what to put in the RewriteCond I'm not sure if there is a IF type statment...
What I currently have is...
RewriteCond %{HTTP_HOST} website\.us$ [NC]
RewriteCond %{HTTP_HOST} !m\.website\.us$ [NC]
RewriteRule ^(.*)$ http://www.website.us/$1 [L,R=301]
Thanks
Try this :
RewriteCond %{HTTP_HOST} !^(www|m)\.website\.us$ [NC]
RewriteRule ^(.*)$ http://www.website.us/$1 [L,R=301]
Related
I have the following set up for an old domain, which works really well to mapping the old pages to the ones on the new domain.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldurl.org.uk [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldurl.org.uk [NC]
RewriteRule ^(.*)$ http://www.newurl.co.uk/$1 [L,R=301,NC]
The problem is I need to redirect the homepage to a specific page on the new URL, keeping the above in tact. Whats the best way to do this?
Thanks in advance!!
You can use:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?oldurl\.org\.uk$ [NC]
RewriteRule ^$ http://www.newurl.co.uk/specificPage [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?oldurl\.org\.uk$ [NC]
RewriteRule ^(.+)$ http://www.newurl.co.uk/$1 [L,R=301]
Let's say may main domain is www.mysite.com and that I'm using the following rewrite in my hataccess
RewriteCond %{HTTP_HOST} !^www.mysite.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
All good so far! However, I also need other domains to redirect to specific pages on the site. For example, if somebody types www.mysite.nl they will be redirected to www.mysite.com/neatherlands. The issue is when I pop the below into my htaccess file I get a server error. I think this is because of the final rewrite. It's a pretty mad set-up
RewriteCond %{HTTP_HOST} !^www\.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.nl$ [NC]
Rewriterule ^(.*)$ http://www.mysite.com/netherlands/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.be$ [NC]
Rewriterule ^(.*)$ http://www.mysite.com/belgium/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.)?mysite\.co.\uk$ [NC]
Rewriterule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
Any suggestions about what to do?
here's my htaccess settings for redirecting urls which don't start with "www." (on my LIVE-environment):
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
i'm also running my mirrored testing environment on a subdomain called test.mydomain.com.
how can i disable this rule for it (as it would always redirect to the live environment)?
thanks
Just add test in your negative RewriteCond like this:
RewriteCond %{HTTP_HOST} !^(www|test)\.
RewriteRule ^(.*)$ http://www.mydomain.com/$1 [R=301,L]
Anubhava's answer worked for me with a small adjustment:
RewriteCond %{HTTP_HOST} !^(www|test)\. [NC]
RewriteRule ^(.*)$ http://www.example.org/$1 [R=301,L]
I have 4 domain which I want 3 of them redirect to last one. I already used some htaccess rules and they are working great,
RewriteEngine On
RewriteCond %{HTTP_HOST} ^first.com$ [NC]
RewriteRule ^(.*) http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.first.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^second.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.second.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^www.third.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^third.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [L,R=301]
the only problem is when I enter "www.first.com/about" it does not shows "www.forth.com/about" just shows the same thing . all the domain are forwarded to forth.com and they do not have hosting so I cannot put htaccess file for those other domains , please guide. would be appreciated.
This is most likely what is happening, at least on my test cases this fix handles it.
Instead of using [L,R=301] reverse the order and do [R=301,L]. The L means Last and it ends cycle on evaluating what to do at that point. I've always used [R=301,L] as are all the examples that I could find anywhere. Potentially your apache may be hitting that L and immediately pass back the new string to the URL parser and isn't sending it as a 301 Redirect as it didn't get that far.
Also on the first.com snippit above you left out the $ on the ^(.*) - only for that line though, not sure if this was a typo or if it's missing in your actual .htaccess file.
Otherwise, you could tidy it up a bit by using:
RewriteCond %{HTTP_HOST} ^((www.)?)first.com [NC,OR]
RewriteCond %{HTTP_HOST} ^((www.)?)second.com [NC,OR]
RewriteCond %{HTTP_HOST} ^((www.)?)third.com [NC]
RewriteRule ^(.*)$ http://www.forth.com/$1 [R=301,L]
I have the following rules in my .htaccess
rewritecond %{http_host} ^oldname.com [nc]
RewriteRule ^(.*)$ http://www.newname.com [r=301,nc]
rewritecond %{http_host} ^www.oldname.com [nc]
rewriterule ^(.*)$ http://www.newname.com [r=301,nc]
I am wondering how to merge does 2 rules in one. Beside that I would like to redirect if user comes to: www.oldname.com/?action=whatever to newname as well...
Thanks for response!
rewritecond %{http_host} ^(www\.)?oldname.com [nc]
RewriteRule ^(.*)$ http://www.newname.com [r=301,nc]
change the above code to that
rewritecond %{http_host} ^(www\.)?oldname.com [nc]
RewriteRule ^(.*)$ http://www.newname.com/$1 [r=301,nc]
If that not work tell me to give you another solution.