Forum Moderators: phranque
I want to point "machine.mycompanywebsite.com" to a long path on another server such as [mycompanywebsite.com...]
My DNS Host is Verio and they will not allow DNS records ending in a path, only a TLD or IP.
My Website is hosted elsewhere with the company who wrote our ECommerce software, I do not have full access to source there.
A Simple redirect will not work because once I have it working, I am sure I will end up with a few machine names pointing to their own specific categories.
I upgraded my Verio account to their minimal account so I can create an .htaccess on Verios recommendation. Although they do not support .htaccess they gave me the following idea
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# Rewrite Rule for machine.forexample-domain.net
RewriteCond %{HTTP_HOST} machine.forexample-domain.net$
RewriteCond %{REQUEST_URI} !machine/
RewriteRule ^(.*)$ machine/$1
So I followed their directions and improvised my information to
RewriteEngine On
Options +FollowSymlinks
RewriteBase /
# Rewrite Rule for machine.mycompanywebsite.com
RewriteCond %{HTTP_HOST} machine.mycompanywebsite.com$
RewriteCond %{REQUEST_URI} !/Categories.aspx?Category=a1b2c3d4-1a2b-1234-5678-4d3c2b1a
RewriteRule ^(.*)$ /Categories.aspx?Category=a1b2c3d4-1a2b-1234-5678-4d3c2b1a $1
My results are a 500 Internal Server Error. Can some one offer any suggestions? Thanks in advance!
The syntax is:
RewriteRule <space> ^regex-pattern-matching-URL-path$ <space> substitution-URL-or-filepath <space> [flags]
It is not clear what you want to do with the originally-requested URL-path, so I cannot advise on that. With the "$1" removed and the corrections noted below, *all* URLs on machine.example.com will be rewritten or redirected to the single path "/Categories.aspx?Category=a1b2c3d4-1a2b-1234-5678-4d3c2b1a"
In addition, REQUEST_URI contains only the URL, and not the query string data appended to that URL. To be clear, a query string is not part of a URL, it is data appended to a URL to be passed to the resource *at* that URL. The "L" in URL stands for "locator" and a query string is not part of the location of a resource.
To fix this, use an additional RewriteCond to check %{QUERY_STRING} for the value you want to match.
Escape the literal periods in your patterns by preceding them with a "\". Otherwise, they are taken as regex tokens meaning "match any single character." e.g., use:
RewriteCond %{HTTP_HOST} ^subdomain\.example\.com If the destination of this "pointing" is actually hosted on a different server, then you do not need the REQUEST_URI and QUERY_STRING checks, but you do need to use a redirect, rather than an internal rewrite:
# Rewrite Rule for machine.example.com
RewriteCond %{HTTP_HOST} machine.example.com$
RewriteRule ^(.*)$ http://www.example.com/Categories.aspx?Category=a1b2c3d4-1a2b-1234-5678-4d3c2b1a $1 [R=301,L]
Jim
Using your sample I couldn't get it to redirect. Using the information you and others provided I was able to get the following to work:
RewriteCond %{HTTP_HOST} machine.example.com
RewriteRule ^$ http://www.example.com/Categories.aspx?Category=a1b2c3d4-1a2b-1234-5678-4d3c2b1a [L]
I guess what they say about a blind squirrel is true.
You still need to escape those literal periods, and I recommend being specific as to whether you want a 301-Moved Permanently redirect or a 302-Found redirect:
RewriteCond %{HTTP_HOST} machin[b]e\.e[/b]xampl[b]e\.c[/b]om
RewriteRule ^$ http://www.example.com/Categories.aspx?Category=a1b2c3d4-1a2b-1234-5678-4d3c2b1a [[b]R=301,[/b]L]
A 301 will tell search engines to list the new URL in their search results, whereas a 302 will tell them to keep the old URL (as long as the old URL is the one that everybody still links to).
Jim