I tried to redirect a mobile site if not contain a text on the url but I receive error.
Can somebody help me please?
I have this code:
RewriteCond %{HTTP_USER_AGENT} iphone|ipad|android|blackberry|ipod [NC]
RewriteCond %{REQUEST_URI} !"?id\=m" [NC]
RewriteRule ^(.*)$ "http\:\/\/blog\.misite\.com\/\?id\=m$1" [R=301,L]
The idea is if are mobile, redirect to blog.misite.com/?id\=m and the rest of URL
but if now contains ?id\=m doesnt redirect.
Thanks!
This probably is what you are looking for:
RewriteCond %{HTTP_USER_AGENT} iphone|ipad|android|blackberry|ipod [NC]
RewriteCond %{QUERY_STRING} !^(?:[^&]*&)*id=m [NC]
RewriteRule ^(.*)$ http://blog.example.com/?id=m$1 [R=301]
Take care however that you do not implement an endless rewriting rule.
Related
I am trying to redirect every URL from my old site to my new site, so that, if someone goes to say oldsite.com/about it redirects to store.newsite.com/about rather than just store.newsite.com/index.php
I tried the following code but for some reason it always takes me to store.newsite.com/index.php when I go to oldsite.com/about instead of taking me to store.newsite.com/about, and the same goes for every other path on the site. Is there something wrong with what I am putting in my .htaccess file?
Thank you!
RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www.oldsite.com [NC]
RewriteRule ^(.*)$ http://store.newsite.com/$1 [L,R=301,NC]
Just fixed it with this code
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old\.site$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.old\.site$ [NC]
RewriteRule ^(.*)$ http://store.newsite.com/$1 [R=301,L]
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]
So the problem I am currently having is that our entire website is indexed using https. we want to redirect to http using .htaccess. the problem is that we need a couple of URIs to still use https and I am not sure how to write the exception for URIs
I know the below example would work if our site functioned like this www.example.com/account.php but our site urls are like www.example.com/index.php?l=account
# Turn SSL on for account
RewriteCond %{HTTPS} off
RewriteCond %{SCRIPT_FILENAME} \/account\.php [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
how can i fix this, any guidance would be appreciated.
thanks
EDIT!
So this code below I have working but I would like to make one more exception that I cant seem to get to work, I also want the root (index.php) to only use http.
I tried using...
RewriteCond %{REQUEST_URI} !^/index.php
but this did not work
# invoke rewrite engine
RewriteEngine On
RewriteBase /
RewriteCond %{https} off
RewriteCond %{QUERY_STRING} !^l=product_detail
RewriteCond %{QUERY_STRING} !^l=product_list
RewriteCond %{QUERY_STRING} !^l=page_view
RewriteRule ^(.*)$ https://%{HTTP_HOST}/development/$1 [R=301,L]
thanks
Try
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/account.php
RewriteCond %{QUERY_STRING} !^l=account
RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/account.php [OR]
RewriteCond %{QUERY_STRING} ^l=account
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
I have an .htaccess redirect script for my mobile detection:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} (iphone|android|nokia|BlackBerry) [NC]
RewriteCond $1 !^mobile/ [NC]
RewriteRule ^(.*)$ http://www.example.com/mobile/ [R=301,L]
When I get redirected to the mobile site, my links don't work that point to:
www.example.com/img0.jpg
If I navigate directly to the site by browsing to:
www.example.com/mobile/
the links work perfectly.
What am I missing in the .htaccess file that is affecting this linking?
Thanks.
EDIT:
I used your script and then added this into the mobile directory, not exactly sure why it works, but it does!
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?mobile\.example\.com$
RewriteCond %{REQUEST_URI} example.com/mobile
RewriteRule ^(.*)$ /mobile/$1 [L]
Try this:
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} (iphone|android|nokia|BlackBerry) [NC]
RewriteCond $1 !^mobile/$1 [NC]
RewriteRule ^(.*)$ http://www.example.com/mobile/$1 [R=301,L]
I need to re-direct a url of a website of mine, if it hasn't the www in it, because of a script that dont work if the url isn't complete, how can i do this with a htacces file, I cant find an example on the web.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]
Something like this might work for you:
RewriteCond %{HTTP:Host} ^(?!www\.)(.+)$ [NC]
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .? http://www.%1%2 [R=301,L]