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

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]

Related

Match complete path of a URL to redirect

I want to redirect a path and all subfolders under this path.
For Example ich want to match the URLs
https://www.joka.de/produktfinder
https://www.joka.de/produktfinder/foo
https://www.joka.de/produktfinder/foo/bar/test.html
The following code works only for the /productfinder but not for productfinder/test
RewriteCond %{HTTP_HOST} ^.*joka.*$ [NC]
RewriteCond %{REQUEST_URI} ^/produktfinder* [NC]
RewriteRule ^(.*)$ https://www.jordan-kassel.de/ausbildung.html [L,R=301]
I think this could be the solution
RewriteCond %{HTTP_HOST} ^.*joka.*$ [NC]
RewriteCond %{REQUEST_URI} ^/produktfinder(.*) [NC]
RewriteRule ^(.*)$ https://www.jordan-kassel.de/ausbildung.html [L,R=301]

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]

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]

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]

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]