Forum Moderators: phranque

Message Too Old, No Replies

Rewrite Syntax Help

         

smsulliva

10:09 pm on Sep 1, 2012 (gmt 0)

10+ Year Member



Hello everyone. This has probably been asked a few times but I didn't find one that may apply to me.
I have a site which I need to rewrite to another URL. We has an old shopping cart on the site and now I want to redirect the user to the new site.
The directory structure is like this:

example.com 
example.com/folder1/
example.com/folder2/
example.com/onlinestore/

Noe the online store is with cgi and I want to redirect anybody that goes to any URL with onlinestore in it to [example2.com...]

Example URLs:

http://example.com/onlinestore/index.cgi?code=3&cat=10
http://mooseburger.com/onlinestore/index.cgi?code=3&cat=22


Here is what I have in my .htaccess file in the root folder:

Options +FollowSymLinks
RewriteEngine On
RewriteRule ^onlinestore.*$ https://example2.com/ [R=301,L]

Any help would be appreciated.

g1smd

10:25 pm on Sep 1, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A rewrite maps a URL request to a non-default internal filepath. The browser address bar continues to show the originally requested URL.

A redirect maps a URL request to a different URL with a new URL request. The browser address bar changes as the new URL request is made.

RewriteRule can be configured to do either of these things and the syntax for both is quite similar. Be sure you know the difference.

lucy24

12:02 am on Sep 2, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Pssst! It has to be "example" but you can vary the tld-- even with names that don't really exist-- as in

http://www.example.shop/
http://www.example.buy/

et cetera.

If this is happening with more than one domain, how will the Redirect know which domain's store it's dealing with?

my .htaccess file in the root folder

Generally when people say "root folder" they mean the same level as their domain's /index.html file. But your example names more than one domain. Are they all in the same userspace, with the .htaccess correspondingly one level higher?

smsulliva

1:03 am on Sep 2, 2012 (gmt 0)

10+ Year Member



Let me explain I made an error on the first post. The two URLS I gave are the same domain. I just forgot to change the second one. What changes for each link is everything after index.cgi.
If I can get some help making my example work I would appreciated it.

The .htaccess file is located in http://example.com/ The onlinestore is one directory below that. There are other page under different folders each with an index.html file.

The new domain I want the redirects to go to is totally different domain and directory structure.

lucy24

8:10 am on Sep 2, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



OK, so far so good, now you need to explain what you want to do. Do you want to capture any part of the original URL and use it in the redirect? Or just grab anything containing the element /onlinestore/ and ship it off to the front page of the new site?

Your current RewriteRule with opening anchor will only work if /onlinestore/ is a top-level directory. It either is or isn't: I assume there's only one of them on your old site. So give the first part of the path, up to and including the /onlinestore/ directory. If you're not capturing the rest of the request you don't even need to look at it.

smsulliva

4:40 pm on Sep 2, 2012 (gmt 0)

10+ Year Member



I don't need to capture anything to use it in the redirect. I just want to grab anything containing the element /onlinestore/ and ship it off to the front page of the new site.

lucy24

3:04 am on Sep 3, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The code you started out with isn't flawless but it seems as if it would work. What's the problem?