Forum Moderators: phranque
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!
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? :)
I actually re-created the /shop/ directory.
I put a new .htaccess in that directory and then
Redirect 301 /shop/ [widgets.com...]
BINGO!
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]
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