Apache Web Server Forum

I am moving a website from a self-managed platform to a hosted solution. It's an e-commerce website.

The idea is to leave a homepage on the self-managed server with links pointing to the new site, which has a sub-domain attached to it.

Domain is www.example.com and the sub-domain is store.example.com.

I have created a rule to do this and it is working fine.

Also, whilst in transition I don't want to disable the old store, I want to re-direct the individual links to products and store categories based on the requested URL. This is because if someone is searching for a particular product, rather than visiting the store front, the results from search engines are for the old store links.

So, I want to be able to redirect any requests for www.example.com/store/product.html to store.example.com/product.html.

Does "example" represent the same word for the new and for the old site?

The code can be much simplified.

Do not escape anything in the target URL of both redirects. Remove the quotes too.

Never redirect to a named index page. The canonical URL for the root page is http://www.example.com/ with a trailing slash.

I'm not sure what you're trying to do witb the second rule. RewriteRule ^example.com http://example.com/ [R=301,L]redirects a request for http://example.com/exampleXcom<anything> or for http://www.example.com/exampleXcom<anything>where X is any character and <anything> is "anything" or "nothing".

(.*) is not an "option". It's a regular expression looking at the path part of the URL request. It means "match any character, zero or more times. To match more "specific" requests, you replace with .* with a more specific pattern.

The last example you gave can never work. The syntax is completely broken.

HTTP_HOST can only match hostname and no other part of the URL request. The RegEx pattern for the rule is completely missing. Move the \/store\/(.*) bit from the Condition to the Rule and change it to ^shop/(.*) and you'll be on the way.

The target URL must not be escaped. Append /$1 to the end of the target, to re-use the captured information in the redirect.

Uh... You've got example.com and store.example.com living in entirely different physical locations? With DNS set up to point requests for store.example.com to the new place and plain example.com to the old place? I'm getting a headache just thinking about it.

What are the Conditions for? RewriteCond %{HTTP_HOST} ^example\.com [OR]RewriteCond %{HTTP_HOST} ^www\.example\.com If this is happening in your old site's htaccess then the host can't be anything but your basic domain, so you don't even need to consider it. A simple, conditionless

RewriteRule ^store/(.*) http://store.example.com/$1 [R=301,L]

should do it.

Other than example.com/store/blahblah which is now going to store.example.com/blahblah, what's left at example.com ?

My input error, the naming convention should be consistent - either store or shop in all uses.

Thanks for your help.

lucy24,As I mentioned, we are moving a store from a self-managed platform to a hosted platform and want to retain full control over the homepage - not limited to the hosted solution framework. So, there is nothing much left on the old site, except for the history etc. We do now have a way of building a more developed homepage.

Thanks for your help with simplifying the RewriteRule.

It is now working as desired, I established that the simple RewriteRule needs to be in the old store subfolder, not the www root, with the rule as

we are moving a store from a self-managed platform to a hosted platform

That was the part I wanted to double check. 99 times out of 100, subdomains will physically live in directories within the directory that contains the primary domain. This means that any requests for the subdomain have to pass through the main domain's config file (and htaccess if any).

But it sounds as if you've got the 100th case, where the two things live in entirely different locations. That means that requests for the subdomain will not pass through the primary domain's config/htaccess, and vice versa. It can make rewrites a lot easier, but it still gives me a headache.

Overlapping g1 here

I established that the simple RewriteRule needs to be in the old store subfolder, not the www root

It can go either way. The main difference is that if the rule is in the (old) root, you need to include "store/" at the beginning of the rule; if it's in the subfolder you don't need it because the request has already been filtered down.

But rules of any kind should be as close to the "top" (config file or root-level htaccess) as possible. Otherwise the server is doing the extra work of sending requests along to the next subdirectory-- when they're going to end up being redirected anyway.