Help with mod_rewrite rule - apache

Need a little help getting the following rule working:
RewriteCond %{HTTP_HOST} ^asset.*.domainone\.com [NC,AND]
RewriteCond %{REQUEST_URI} !^/FILE/.* [NC]
RewriteRule ^(.*)$ "http://domaintwo\.com/$1" [L]
For requests coming to this server with a domain of 'asset(anything).domain.com' which does not start with 'FILE', redirect to another server.
Thanks.

RewriteCond %{HTTP_HOST} ^asset.*?\.domainone\.com [NC]
RewriteCond %{REQUEST_URI} !^/FILE/.* [NC]
RewriteRule ^/(.*)$ http://domaintwo.com/$1 [R,L]

Related

Apache redirect with RewriteCond not working

I am looking a way to rewrite the below url:
faleconosco.aeiou.com.br/Email.do?tela=2&auth=N&skin=Sac
to
10.13.2.1:9080
I already tried several differents ways: All not worked
Any help will be glad
RewriteCond %{REQUEST_URI} =contact/Email\.do?tela=2&auth=N&skin=Sac [NC]
RewriteRule http://10.13.2.1:9080 [R=301,L]
RewriteCond %{HTTP_HOST} =faleconosco.aeiou.com.br/contact/Email.do?tela=2&auth=N&skin=Sac
RewriteRule ^(.*)$ 10.13.2.1:9080/$1 [R=301]
RewriteCond %{HTTP_HOST} (a-z).aeiou.com.br/contact/Email.do?tela=2&auth=N&skin=Sac
RewriteRule ^(.*)$ 10.13.2.1:9080/$1 [R=301]
Any assistance will be glad

Redirecting to https for any URI

In my .htaccess file, I have the below.
RewriteCond %{HTTPS} !on [OR]
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://www.example.com%{REQUEST_URI} [R=301]
This works fine until someone goes to http://www.example.com/test because that does not force a redirect to https.
Is there a better way of doing this?
Yes, change your last two lines to:
RewriteCond %{HTTP_HOST} !^(www\.example\.com|)$ [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]

.htaccess domain-1/directory-x to domain2.directory-y

How would I, with .htaccess, do the following
RewriteCond %{HTTP_HOST} ^(www.)?domain-1\.com$ [NC]
RewriteCond %{REQUEST_URI} /posts/([a-z0-9_]+)
RewriteRule ^(.*)$ https://www.domain-2\.com/articles/$1 [L,R=301]
So that "/posts/" does not become part of the forwarded path?
Example, I want
http://www.domain-1.com/posts/2014/06/17/some-post-title
To forward to
https://www.domain-2.com/articles/2014/06/17/some-post-title
Thank you for any help.
You can use:
RewriteCond %{HTTP_HOST} ^(www\.)?domain-1\.com$ [NC]
RewriteRule ^posts/(.*)$ https://www.domain-2.com/articles/$1 [L,R=301,NE]

Prevent redirect coming from external domains

I need to prevent that an external domain make a redirect to my domain. I tried using the following rules:
RewriteCond %{HTTP_REFERER} ^http://www.extenaldomain.com [NC]
RewriteRule ^$ /my_error_page.htm [R,L]
but it doesn't work. I tried also:
RewriteCond %{HTTP_FORWARDED} ^http://www.extenaldomain.com [NC]
RewriteRule ^$ /my_error_page.htm [R,L]
but it doesn't work too. any idea?
Why don't you simply precise the domain name without adding extra stuff?
Try this, it should work:
RewriteCond %{HTTP_REFERER} extenaldomain\.com [NC]
RewriteRule (.*) /my_error_page.htm [R,L]
Tell me if it does
SOLVED: it works:
RewriteCond %{HTTP_REFERER} extenaldomain\.com [NC]
RewriteCond %{REQUEST_URI} !^/my_error_page.htm
RewriteRule (.*) /my_error_page.htm [R,L]

Redirect with .htaccess

i have a pointed domain keepyourlinks.com on my cpanel of piscolabis.info, so if you go to piscolabis.info/keepyourlinks.com/ you acces it and i don't want that, i'm trying:
RewriteCond %{HTTP_HOST} ^piscolabis.info/keepyourlinks.com/ [NC]
RewriteRule ^(.*)$ http://keepyourlinks.com/$1 [L,R=301]
But it doesn't work... :S
This should work:
RewriteCond %{HTTP_HOST} ^piscolabis.info$
RewriteCond %{REQUEST_URI} ^/keepyourlinks.com [NC]
RewriteRule ^(.*)$ http://keepyourlinks.com/$1 [L,R=301]