Glen Glen - 6 days ago 5
Apache Configuration Question

.htaccess redirect with query string on subdomain isn't working

I am trying to use htaccess to redirect a URL like:

http://subdomain.domain.com/[anytexthere]/ to redirect to

http://www.domain2.com/something/something/[theanytexthere]/

But all I keep getting is a 404 error when trying to access http://subdomain.domain.com/test/, here is the .htaccess sample:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain.domain.com$ [NC]
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule http://www.domain2.com/some/path/%1/ [R=301,L]

Answer

There is no query string in your source or target URL. You just need REQUEST_URI to be redirected.

You can use this rule:

RewriteEngine On

RewriteCond %{HTTP_HOST} =subdomain.domain.com
RewriteRule ^ http://www.domain2.com/some/path%{REQUEST_URI} [R=301,L,NC,NE]