Hi i have a site with drupal and i use a module for make redirection depending of the agent, if mobile redirect to http://m.url.com but if no, stay in desktop site, but i want to redirect always to http://www.url.com if you write url.com for this, i use this
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI}[L,R=301]
but this no works for me, because i use a module to redirect to mobile site, then, if use the code before always redirect to www.url.com but in mobile also, redirect to www.m.url.com and no working for mobile site, please how to make a exception in the code before, always redirect to www.url.com except m.url.com
thanks
Solution
with the answer before, i resolve for this way
RewriteCond %{HTTP_HOST} ^url.com
RewriteCond %{HTTP_HOST} !^m.url.com
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
You can use:
RewriteCond %{HTTP_HOST} !^(?:www|m)\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Related
I want to verifiy that if my redirection code is implemeted good to dont have problems in seo.
Currently using this code:
I want to do this:
- http://mydomain.tld to https://www.mydomain.tld
- http://www.mydomain.tld to https://www.mydomain.tld
My currently code is:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Currently is redirecting but I dont know if 301 is implemented good?
If you're concerned if a redirect is having a negative impact on organic rank, such as multiple redirects (rather than one clean redirect), you can use this tool to check each redirect 'hop':
RedirectDetective.com
I have a website on a domain that I want to move to another domain. Here is my problem. The root URL has to redirect to a different location on the new domain. Example:
http://subdomain.olddomain.com/ must redirect to http://www.newdomain.com/location
http://subdomain.olddomain.com/code/slug must redirect to http://www.newdomain.com/slug
The htaccess code that I have doesn't work ver
RewriteRule ^/?(.*) http://www.newdomain.com/$1 [R=302,L]
This code works for the second example, but nog on the first. Can anyone help me setup the correct htaccess code?
Try:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^code/(.*)$ http://www.newdomain.com/$1 [L,R]
RewriteCond %{HTTP_HOST} ^subdomain\.olddomain\.com$ [NC]
RewriteRule ^$ http://www.newdomain.com/location [L,R]
Well it's kind of hard typing a title to describe what I want to do.
Basically I have a website that I've been asked to develop a mobile site for. This website has various domains (such as .co.za,.com,.za.net) but they all run from the same folder on the server (so I only have one .htaccess file).
I want to be able to redirect the traffic that goes to www.example.co.za to m.example.co.za and traffic that goes to www.example.com to m.example.com.
How would I need to modify this .htaccess file to achieve that.
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} "alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte" [NC]
RewriteRule ^$ http://m.example.com/ [L,R=302]
How about:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} "alcatel|amoi|android|avantgo|blackberry|benq|cell|cricket|docomo|elaine|htc|iemobile|iphone|ipad|ipaq|ipod|j2me|java|midp|mini|mmp|mobi|motorola|nec-|nokia|palm|panasonic|philips|phone|playbook|sagem|sharp|sie-|silk|smartphone|sony|symbian|t-mobile|telus|up\.browser|up\.link|vodafone|wap|webos|wireless|xda|xoom|zte" [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?(.*)$ [NC]
RewriteRule ^(.*)$ http://m.%2/ [L,R=302]
The web page at http://www.gls.in/ has resulted in too many redirects. Clearing your cookies for this site or allowing third-party cookies may fix the problem. If not, it is possibly a server configuration issue and not a problem with your computer.
Here are some suggestions:
Reload this web page later.
Learn more about this problem.
Error 310 (net::ERR_TOO_MANY_REDIRECTS): There were too many redirects.
RewriteCond %{HTTP_HOST} ^gls\.in$ [OR]
RewriteCond %{HTTP_HOST} ^www\.gls\.in$
RewriteRule ^/?$ "http\:\/\/www\.gls\.in\/" [R=301,L]
The problem is the last line:
RewriteCond %{HTTP_HOST} ^gls\.in$ [OR]
RewriteCond %{HTTP_HOST} ^www\.gls\.in$
RewriteRule ^/?$ "http\:\/\/www\.gls\.in\/" [R=301,L]
What exactly do you want to achive by that?
If you always want to redirect to www.gls.in then remove the second RewriteCond and rewrite every access.
RewriteCond %{HTTP_HOST} ^gls\.in$
RewriteRule .* "http\:\/\/www\.gls\.in\/" [R=301,L]
I want to :
- switch from http to https if http is used
- redirect the subdomain to index?o=subdomain except www
- redirection the subdirectory to index?u=user
Example :
http://www.mydomain.com will be redirected to https://www.mydomain.com
http://subdomain.mydomain.com will be redirected to https://www.mydomain.com/index?o=subdomain
https://subdomain.mydomain.com will be redirected to https://www.mydomain.com/index?o=subdomain
http://subdomain.mydomain.com/user will be redirected to https://www.mydomain.com/index?o=subdomain&u=user
https://subdomain.mydomain.com/user will be redirected to https://www.mydomain.com/index?o=subdomain&u=user
Is mod_Rewrite the best to do that ? Any idea ?
Thanks in advance
I don't have time to test it right now, but you can try this and see if it works. There may be some potential for some things to go wrong, so if you have trouble with it I'd be happy to work out any kinks later. Also, I think that I covered everything you wanted to do, but let me know if I left something out.
RewriteEngine On
# Force redirect to HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule ^.*$ https://%{HTTP_HOST}/$0 [R=301,L]
Edit: I've updated the ruleset below. I thought about your question though, and aren't you going to have issues attempting to serve up your subdomains over TLS/SSL? That aside, one of the following should do what you want (without errors this time, I hope):
If you wanted internal redirection:
RewriteCond %{HTTP_HOST} !=mydomain.com
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{REQUEST_URI} !^/index
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^\.]+)[^/]*/([^/]+)?
RewriteCond %1&u=%2 ^([^&]+)(&u=.+)?
RewriteRule ^.*$ /index?o=%1%2
If you wanted external redirection:
RewriteCond %{HTTP_HOST} !=mydomain.com
RewriteCond %{HTTP_HOST} !^www
RewriteCond %{REQUEST_URI} !^/index
RewriteCond %{HTTP_HOST}%{REQUEST_URI} ^([^\.]+)[^/]*/([^/]+)?
RewriteCond %1&u=%2 ^([^&]+)(&u=.+)?
RewriteRule ^.*$ https://www.mydomain.com/index?o=%1%2 [R=301,L]