Forum Moderators: phranque

Message Too Old, No Replies

Please help. weird .htaccess issue.

         

phi148

6:45 pm on Jan 1, 2007 (gmt 0)

10+ Year Member



Ok folks, happy new year! Please read my little story below, and see what you think. I really need help here. I have searched around, but just can't find the help I need. I have masked my real store name with www.widgets.com.

When my website first launched, my online store was located here [widgets.com...]

about 2 months down the line I DELETED /shop/ and moved everything to the root level
[widgets.com...]

Now... here's the weird part. You would think that all of the old cached links with the "/shop/" in the path would no longer work..... NOT TRUE! :)

For example : [widgets.com...]
That path DOES NOT EXIST, but the link works!

Heck, you could put JOETEST in place of /shop/ and it will still work : [widgets.com...]

Why? Because of .htaccess. I did not do this intentionally just to save the old /shop/ links. I implemented SEO friendly URL's ( a contribution from OScommerce ) and this is part of the install.

Well.. now that my store is moved, I'm stuck with the search engines showing the old /shop/ links! I don't want this at all. /shop/ does no longer exist, and I want it gone from the search engines.

Can anybody help me out here... or am I stuck?
Here is my .htaccess :

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

RewriteRule ^(.*)-p-(.*).html$ product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-([0-9]+).html$ index.php?manufacturers_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pi-([0-9]+).html$ popup_image.php?pID=$2&%{QUERY_STRING}
RewriteRule ^(.*)-t-([0-9]+).html$ articles.php?tPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-a-([0-9]+).html$ article_info.php?articles_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pr-([0-9]+).html$ product_reviews.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pri-([0-9]+).html$ product_reviews_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-i-([0-9]+).html$ information.php?info_id=$2&%{QUERY_STRING}

RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST}!^www\.widgets\.com [NC]
RewriteRule (.*) [widgets.com...] [R=301,L]

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ [widgets.com...] [R=301,L]

RedirectMatch permanent ^/shop/$ [widgets.com...]
RedirectMatch permanent ^/shop$ [widgets.com...]

Thanks!

phi148

6:47 pm on Jan 1, 2007 (gmt 0)

10+ Year Member



If you want to see the real website .. PLEASE PM me and I'll send you the link!

Thanks all!

phi148

7:25 pm on Jan 1, 2007 (gmt 0)

10+ Year Member



OK... I think I know what I need. I'm not an expert with .htaccess...
so I don't know how to write this, but it needs to do this :

IF /shop/ is in the path THEN

Redirect 301 /shop/ [widgets.com...]

ELSE (Do the other stuff)

RewriteRule ^(.*)-p-(.*).html$
product_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-c-(.*).html$ index.php?cPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-m-([0-9]+).html$
index.php?manufacturers_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pi-([0-9]+).html$
popup_image.php?pID=$2&%{QUERY_STRING}
RewriteRule ^(.*)-t-([0-9]+).html$
articles.php?tPath=$2&%{QUERY_STRING}
RewriteRule ^(.*)-a-([0-9]+).html$
article_info.php?articles_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pr-([0-9]+).html$
product_reviews.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-pri-([0-9]+).html$
product_reviews_info.php?products_id=$2&%{QUERY_STRING}
RewriteRule ^(.*)-i-([0-9]+).html$
information.php?info_id=$2&%{QUERY_STRING}

END IF

Can somebody help me write that IF statement in .htaccess? :)

phi148

7:41 pm on Jan 1, 2007 (gmt 0)

10+ Year Member



Well... I got it!

I actually re-created the /shop/ directory.

I put a new .htaccess in that directory and then

Redirect 301 /shop/ [widgets.com...]

BINGO!

jdMorgan

8:26 pm on Jan 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This forum isn't very lively on weekends and holidays, so sorry for the delay in getting a response.

The most likely cause of your problem is the use of the 'promiscuous' ".*" pattern in your rules. The ".*" pattern will match anything and everything, meaning that your patterns are ambiguous. You should use a more-specific pattern, for example:


RewriteRule ^([^/-]+)-p-([^.]+)\.html$ /product_info.php?products_id=$2 [QSA,L]

Here, the first pattern accepts any number of characters that are *not* a slash or a hyphen, and the second pattern accepts any number of characters that are *not* a period. So, because the slash is excluded, only URLs in your top-level directory will be rewritten. This more-specific pattern also allows URLs to be matched in a single left-to-right pass, unlike the multiple 'backoff-and-retry' passes that will be required if you use ".*".

Another way of looking at those negative-match patterns is that the first one says, "Match all the characters up to the next slash or hyphen."

I had a bit of a hand in the friendly URL stuff for oscommerce (see the documentation), and if they ended up publishing rewrite rule patterns with ".*" in them, I regret that. ".*" is easy use, but horribly inefficient and likely to cause unexpected results.

It should not be necessary to 'manually' include the query string in the substitution; You can use the [QSA' flag for that. Also, always use an [L] flag unless you know a very good reason why you should not use it. Using the [L] flag prevents your server from wasting time trying to apply all the following rewrites to a previously-rewritten URL.

The second most likely cause for your /shop URLs still working after deleting the directory is that MultiViews are turned on. When MultiViews are enabled, the server will try to find a 'best fit' match if a requested URL does not exist. This is part of Apache content-negotiation, and with the default negotiation rules, the effect you see can and does happen.

So the concern you implied --duplicate content problems caused by multiple URLs resolving to the same page-- is a big one when MultViews are enabled. As a result, I always disable MultiViews if it can be done without breaking some previously-installed script. This is a simple matter of adding another token to the Options directive:


Options +FollowSymLinks -MultiViews

Jim