Redirect with .htaccess - apache

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]

Related

Multiple domains on one host https and http

I have multiple domains on one host, my .htaccess looks like this
RewriteEngine On
RewriteCond %{HTTP_HOST} web1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_1/public/.*$
RewriteRule ^(.*)$ /web_1/public/$1 [L]
RewriteCond %{HTTP_HOST} web2.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_2/public/.*$
RewriteRule ^(.*)$ /web_2/public/$1 [L]
And it works so far. Now I want only web1.com, not web2.com, to redirect to https. How do I have to change the settings? (I am also thankful for tips about how to change my "implementation" so far, I am new to .htaccess and willing to learn more about it)
Try this :
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} web2.com$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
So , your rules will look like this :
RewriteEngine On
RewriteCond %{HTTP_HOST} web1.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_1/public/.*$
RewriteRule ^(.*)$ /web_1/public/$1 [L]
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} web2.com$ [NC]
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP_HOST} web2.com$ [NC]
RewriteCond %{REQUEST_URI} !^/web_2/public/.*$
RewriteRule ^(.*)$ /web_2/public/$1 [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]

Merge htaccess HTTP_HOST Rewrite Cond

i have this htaccess conditions...
# changed... subdomains to subdirectories...
RewriteCond %{HTTP_HOST} ^acoruna.domain\.es [nc]
RewriteRule (.*) http://domain.es/acoruna/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^alava.domain\.es [nc]
RewriteRule (.*) http://domain.es/alava/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^albacete.domain\.es [nc]
RewriteRule (.*) http://domain.es/albacete/$1 [R=301,L]
# changed... subdomains to subdirectories...
My question is,, can i merge all that RewriteCond & Rewrite Rules, in only 1? because all do the same.
Thanks, regards from Spain.
Try:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.es$ [NC]
RewriteRule ^(.*)$ http://domain.es/%1/$1 [R=301,L]

force non www to www in htaccess

I have:
# BEGIN WithoutWWW
RewriteEngine On
RewriteCond %{HTTP_HOST} ^mysite.com [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [L,R=301]
# END WithoutWWW
But it won't work. I can still access both www and non www versions. What am I doing wrong?
Try:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC]
RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]
//OR
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule (.*) http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.mysite\.com [NC]
RewriteRule ^(.*)$ [R=301,L]

Help with mod_rewrite rule

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]